aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorHongbin Zheng <etherzhhb@gmail.com>2017-09-29 16:32:12 +0000
committerHongbin Zheng <etherzhhb@gmail.com>2017-09-29 16:32:12 +0000
commitc8abdf5f2509067052e5845d3d8a0e21020f628a (patch)
treeb3d7372733104c0e88404b5d0904d49f9c939e30 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parentc2e79c2dfc07e1aba27946f22ea370cd5c130b04 (diff)
downloadllvm-c8abdf5f2509067052e5845d3d8a0e21020f628a.zip
llvm-c8abdf5f2509067052e5845d3d8a0e21020f628a.tar.gz
llvm-c8abdf5f2509067052e5845d3d8a0e21020f628a.tar.bz2
[SimplifyIndVar] Do not fail when we constant fold an IV user to ConstantPointerNull
The type of a SCEVConstant may not match the corresponding LLVM Value. In this case, we skip the constant folding for now. TODO: Replace ConstantInt Zero by ConstantPointerNull llvm-svn: 314531
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index cef8fe1..9608814 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -546,18 +546,25 @@ bool SimplifyIndvar::foldConstantSCEV(Instruction *I) {
const Loop *L = LI->getLoopFor(I->getParent());
S = SE->getSCEVAtScope(S, L);
+ auto *C = dyn_cast<SCEVConstant>(S);
- if (auto *C = dyn_cast<SCEVConstant>(S)) {
- I->replaceAllUsesWith(C->getValue());
- DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I
- << " with constant: " << *C << '\n');
- ++NumFoldedUser;
- Changed = true;
- DeadInsts.emplace_back(I);
- return true;
- }
+ if (!C)
+ return false;
- return false;
+ Constant *V = C->getValue();
+ // The SCEV will have a different type than the instruction if the instruction
+ // has a pointer type. Skip the replacement
+ // TODO: Replace ConstantInt Zero by ConstantPointerNull
+ if (V->getType() != I->getType())
+ return false;
+
+ I->replaceAllUsesWith(V);
+ DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I << " with constant: " << *C
+ << '\n');
+ ++NumFoldedUser;
+ Changed = true;
+ DeadInsts.emplace_back(I);
+ return true;
}
/// Eliminate any operation that SCEV can prove is an identity function.