diff options
author | Chris Lattner <sabre@nondot.org> | 2011-02-17 22:21:26 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-02-17 22:21:26 +0000 |
commit | 4bd8217af3cf38f9fcce378fbc687162e28a7cf8 (patch) | |
tree | 2563d191093c4e023a03f0970a0e5591bf43bdf2 /lib/Transforms/InstCombine/InstCombinePHI.cpp | |
parent | 093399cbf3bcdb31d04b3bf5c5691fc88c25da48 (diff) |
fix instcombine merging GEPs through a PHI to only make the
result inbounds if all of the inputs are inbounds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125785 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombinePHI.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombinePHI.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstCombinePHI.cpp b/lib/Transforms/InstCombine/InstCombinePHI.cpp index 736473db1d..a1aa2dff11 100644 --- a/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/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; } |