]> granicus.if.org Git - llvm/commitdiff
Avoid output indeterminism between GCC and Clang builds.
authorPatrik Hagglund <patrik.h.hagglund@ericsson.com>
Mon, 20 Jun 2016 10:19:04 +0000 (10:19 +0000)
committerPatrik Hagglund <patrik.h.hagglund@ericsson.com>
Mon, 20 Jun 2016 10:19:04 +0000 (10:19 +0000)
Remove dependency of the evalution order of function arguments, which
is unspecified.

Patch by David Stenberg.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273145 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolutionExpander.cpp

index bcc4381ebf48cd40c099450acbf4bd31f35c71a5..77164356d8e19fe4258f6a4ec8987305b1424eb8 100644 (file)
@@ -1443,8 +1443,12 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
     }
 
     // Just do a normal add. Pre-expand the operands to suppress folding.
-    return expand(SE.getAddExpr(SE.getUnknown(expand(S->getStart())),
-                                SE.getUnknown(expand(Rest))));
+    //
+    // The LHS and RHS values are factored out of the expand call to make the
+    // output independent of the argument evaluation order.
+    const SCEV *AddExprLHS = SE.getUnknown(expand(S->getStart()));
+    const SCEV *AddExprRHS = SE.getUnknown(expand(Rest));
+    return expand(SE.getAddExpr(AddExprLHS, AddExprRHS));
   }
 
   // If we don't yet have a canonical IV, create one.