[llvm-commits] [llvm] r112432 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Dan Gohman gohman at apple.com
Sun Aug 29 08:10:06 PDT 2010


Author: djg
Date: Sun Aug 29 10:10:06 2010
New Revision: 112432

URL: http://llvm.org/viewvc/llvm-project?rev=112432&view=rev
Log:
Batch up subtracts along with adds, when analyzing long chains of
operations.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=112432&r1=112431&r2=112432&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sun Aug 29 10:10:06 2010
@@ -3332,11 +3332,16 @@
     // LLVM IR canonical form means we need only traverse the left operands.
     SmallVector<const SCEV *, 4> AddOps;
     AddOps.push_back(getSCEV(U->getOperand(1)));
-    for (Value *Op = U->getOperand(0);
-         Op->getValueID() == Instruction::Add + Value::InstructionVal;
-         Op = U->getOperand(0)) {
+    for (Value *Op = U->getOperand(0); ; Op = U->getOperand(0)) {
+      unsigned Opcode = Op->getValueID() - Value::InstructionVal;
+      if (Opcode != Instruction::Add && Opcode != Instruction::Sub)
+        break;
       U = cast<Operator>(Op);
-      AddOps.push_back(getSCEV(U->getOperand(1)));
+      const SCEV *Op1 = getSCEV(U->getOperand(1));
+      if (Opcode == Instruction::Sub)
+        AddOps.push_back(getNegativeSCEV(Op1));
+      else
+        AddOps.push_back(Op1);
     }
     AddOps.push_back(getSCEV(U->getOperand(0)));
     return getAddExpr(AddOps);





More information about the llvm-commits mailing list