diff --git a/Compiler/BackEnd/BackendDAECreate.mo b/Compiler/BackEnd/BackendDAECreate.mo index c7391050e74..c3e5eff65a7 100644 --- a/Compiler/BackEnd/BackendDAECreate.mo +++ b/Compiler/BackEnd/BackendDAECreate.mo @@ -1050,7 +1050,7 @@ protected function lowerIfEquation input list inEqns; output list outEqns; algorithm - outEqn := matchcontinue(conditions,theneqns,elseenqs,conditions1,theneqns1,source,functionTree,inEqns) + outEqns := matchcontinue(conditions,theneqns,elseenqs,conditions1,theneqns1,source,functionTree,inEqns) local DAE.Exp e; list explst; diff --git a/Compiler/BackEnd/BackendDAEOptimize.mo b/Compiler/BackEnd/BackendDAEOptimize.mo index 796e70bd3fb..2445bdbd40f 100644 --- a/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/Compiler/BackEnd/BackendDAEOptimize.mo @@ -3310,7 +3310,6 @@ algorithm remeqns = BackendDAEUtil.listEquation(eqnslst); // do replacements in systems systs = List.map1(systs,removeProtectedParameterswork,repl); - BackendDump.dump(BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,av,inieqns,remeqns,constrs,cache,env,funcs,einfo,eoc,btp,symjacs))); then BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,av,inieqns,remeqns,constrs,cache,env,funcs,einfo,eoc,btp,symjacs)); end match; diff --git a/Compiler/BackEnd/BackendVarTransform.mo b/Compiler/BackEnd/BackendVarTransform.mo index dc63d4a955f..53db54f71f9 100644 --- a/Compiler/BackEnd/BackendVarTransform.mo +++ b/Compiler/BackEnd/BackendVarTransform.mo @@ -1154,8 +1154,9 @@ algorithm source = DAEUtil.addSymbolicTransformationSimplifyLst(blst,source,expl1,expl2); eqnslst = List.map2(eqnslst,replaceEquations2,repl,{}); eqns = replaceEquations2(eqns,repl,{}); + eqns = optimizeIfEquation(expl2,eqnslst,eqns,{},{},source,inAcc); then - replaceEquations2(es,repl,BackendDAE.IF_EQUATION(expl2,eqnslst,eqns,source)::inAcc); + replaceEquations2(es,repl,eqns); case ((a :: es),repl,_) equation @@ -1165,6 +1166,49 @@ algorithm end matchcontinue; end replaceEquations2; +protected function optimizeIfEquation + input list conditions; + input list> theneqns; + input list elseenqs; + input list conditions1; + input list> theneqns1; + input DAE.ElementSource source; + input list inEqns; + output list outEqns; +algorithm + outEqn := matchcontinue(conditions,theneqns,elseenqs,conditions1,theneqns1,source,inEqns) + local + DAE.Exp e; + list explst; + list> eqnslst; + list eqns; + + // no true case left with condition<>false + case ({},{},_,{},{},_,_) + then + listAppend(elseenqs,inEqns); + // true case left with condition<>false + case ({},{},_,_,_,_,_) + equation + explst = listReverse(conditions1); + eqnslst = listReverse(theneqns1); + then + BackendDAE.IF_EQUATION(explst,eqnslst,elseenqs,source)::inEqns; + // if true use it + case(DAE.BCONST(true)::_,eqns::_,_,_,_,_,_) + then + eqns; + // if false skip it + case(DAE.BCONST(false)::explst,_::eqnslst,_,_,_,_,_) + then + optimizeIfEquation(explst,eqnslst,elseenqs,conditions1,theneqns1,source,inEqns); + // all other cases + case(e::explst,eqns::eqnslst,_,_,_,_,_) + then + optimizeIfEquation(explst,eqnslst,elseenqs,e::conditions1,eqns::theneqns1,source,inEqns); + end matchcontinue; +end optimizeIfEquation; + protected function replaceWhenEquation "Replaces variables in a when equation" input BackendDAE.WhenEquation whenEqn; input VariableReplacements repl; diff --git a/Compiler/Util/Flags.mo b/Compiler/Util/Flags.mo index 9ba48bf9e4b..32efae6fbbe 100644 --- a/Compiler/Util/Flags.mo +++ b/Compiler/Util/Flags.mo @@ -499,7 +499,7 @@ constant ConfigFlag NO_SIMPLIFY = CONFIG_FLAG(11, "noSimplify", protected constant String removeSimpleEquationDesc = "Performs alias elimination and removes constant variables from the DAE, replacing all occurrences of the old variable reference with the new value (constants) or variable reference (alias elimination)."; public constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules", NONE(), EXTERNAL(), STRING_LIST_FLAG({ - "evaluateParameters", +// "evaluateParameters", "removeFinalParameters", "removeEqualFunctionCalls", "partitionIndependentBlocks",