summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-17 22:21:26 +0000
committerChris Lattner <sabre@nondot.org>2011-02-17 22:21:26 +0000
commitabb8eb2c63c4e272c4bad4490df8c32a69e7812f (patch)
treecc85ac918e0cf1c9f3fdc863ea7a1748356b994d /llvm/lib/Transforms
parentfb59c7c7d878cbbcb9351316abf840b70e38c07a (diff)
downloadbcm5719-llvm-abb8eb2c63c4e272c4bad4490df8c32a69e7812f.tar.gz
bcm5719-llvm-abb8eb2c63c4e272c4bad4490df8c32a69e7812f.zip
fix instcombine merging GEPs through a PHI to only make the
result inbounds if all of the inputs are inbounds. llvm-svn: 125785
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 736473db1d5..a1aa2dff11a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -118,6 +118,8 @@ Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
// especially bad when the PHIs are in the header of a loop.
bool NeededPhi = false;
+ bool AllInBounds = true;
+
// Scan to see if all operands are the same opcode, and all have one use.
for (unsigned i = 1; i != PN.getNumIncomingValues(); ++i) {
GetElementPtrInst *GEP= dyn_cast<GetElementPtrInst>(PN.getIncomingValue(i));
@@ -125,6 +127,8 @@ Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
GEP->getNumOperands() != FirstInst->getNumOperands())
return 0;
+ AllInBounds &= GEP->isInBounds();
+
// Keep track of whether or not all GEPs are of alloca pointers.
if (AllBasePointersAreAllocas &&
(!isa<AllocaInst>(GEP->getOperand(0)) ||
@@ -202,11 +206,11 @@ Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
}
Value *Base = FixedOperands[0];
- return cast<GEPOperator>(FirstInst)->isInBounds() ?
- GetElementPtrInst::CreateInBounds(Base, FixedOperands.begin()+1,
- FixedOperands.end()) :
+ GetElementPtrInst *NewGEP =
GetElementPtrInst::Create(Base, FixedOperands.begin()+1,
FixedOperands.end());
+ if (AllInBounds) NewGEP->setIsInbounds();
+ return NewGEP;
}
OpenPOWER on IntegriCloud