summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-31 22:53:17 +0000
committerDan Gohman <gohman@apple.com>2010-08-31 22:53:17 +0000
commit3f19c091bf9cfe717e14b8a1967085ba84db3877 (patch)
treefef224bbac815d247004bb42bffa056e52539e70
parent6a0c125ed566d3d2fecd70b9dcac65ef10b7958a (diff)
downloadllvm-3f19c091bf9cfe717e14b8a1967085ba84db3877.tar.gz
llvm-3f19c091bf9cfe717e14b8a1967085ba84db3877.tar.bz2
llvm-3f19c091bf9cfe717e14b8a1967085ba84db3877.tar.xz
Reapply r112432, now that the real problem is addressed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112667 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/ScalarEvolution.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 795232b7ce..b892d85f9f 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -3332,11 +3332,16 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
// 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);