Skip to content

Commit

Permalink
Optimize max({arr})->max(arr) instead of arr
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 1, 2016
1 parent 26ec49e commit d65644e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1067,16 +1067,23 @@ algorithm
// If the argument to min/max is an array, try to flatten it.
case (DAE.CALL(path=Absyn.IDENT(name),expLst={e as DAE.ARRAY()},
attr=DAE.CALL_ATTR(ty=tp)))
guard name=="max" or name=="min"
equation
true = stringEq(name, "max") or stringEq(name, "min");
expl = Expression.flattenArrayExpToList(e);
e1 = Expression.makeScalarArray(expl, tp);
false = Expression.expEqual(e, e1);
then
Expression.makePureBuiltinCall(name, {e1}, tp);

// min/max function on arrays of only 1 element
case (DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ARRAY(array={e})})) then e;
case (DAE.CALL(path=Absyn.IDENT(name),expLst={DAE.ARRAY(array=expl as {e})}))
guard name=="max" or name=="min"
algorithm
if Expression.isArrayType(Expression.typeof(e)) then
exp.expLst := expl;
e := exp;
end if;
then e;
case (DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ARRAY(array={e})})) then e;

case (DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ARRAY(array=es)},attr=DAE.CALL_ATTR(ty=tp)))
Expand Down

0 comments on commit d65644e

Please sign in to comment.