diff --git a/lib/Dialect/BaseModelica/Transforms/CallCSE.cpp b/lib/Dialect/BaseModelica/Transforms/CallCSE.cpp index 7a6ddba94..979c4b139 100644 --- a/lib/Dialect/BaseModelica/Transforms/CallCSE.cpp +++ b/lib/Dialect/BaseModelica/Transforms/CallCSE.cpp @@ -31,16 +31,18 @@ class CallCSEPass final : public impl::CallCSEPassBase { /// Get all call operations in the model. void collectCallOps(ModelOp modelOp, llvm::SmallVectorImpl &callOps) { - llvm::SmallVector initialEquationOps; llvm::SmallVector dynamicEquationOps; - - modelOp.collectInitialEquations(initialEquationOps); modelOp.collectMainEquations(dynamicEquationOps); - llvm::DenseSet templateOps; + llvm::SmallVector templateOps; for (EquationInstanceOp equationOp : dynamicEquationOps) { - templateOps.insert(equationOp.getTemplate()); + EquationTemplateOp templateOp = equationOp.getTemplate(); + if (!templateOp.getInductionVariables().empty() && + llvm::is_contained(templateOps, templateOp)) { + continue; + } + templateOps.push_back(templateOp); } for (EquationTemplateOp templateOp : templateOps) {