llvm.org GIT mirror llvm / 4bd8217
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 Chris Lattner 8 years ago
2 changed file(s) with 10 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
117117 // especially bad when the PHIs are in the header of a loop.
118118 bool NeededPhi = false;
119119
120 bool AllInBounds = true;
121
120122 // Scan to see if all operands are the same opcode, and all have one use.
121123 for (unsigned i = 1; i != PN.getNumIncomingValues(); ++i) {
122124 GetElementPtrInst *GEP= dyn_cast(PN.getIncomingValue(i));
124126 GEP->getNumOperands() != FirstInst->getNumOperands())
125127 return 0;
126128
129 AllInBounds &= GEP->isInBounds();
130
127131 // Keep track of whether or not all GEPs are of alloca pointers.
128132 if (AllBasePointersAreAllocas &&
129133 (!isa(GEP->getOperand(0)) ||
201205 }
202206
203207 Value *Base = FixedOperands[0];
204 return cast(FirstInst)->isInBounds() ?
205 GetElementPtrInst::CreateInBounds(Base, FixedOperands.begin()+1,
206 FixedOperands.end()) :
208 GetElementPtrInst *NewGEP =
207209 GetElementPtrInst::Create(Base, FixedOperands.begin()+1,
208210 FixedOperands.end());
211 if (AllInBounds) NewGEP->setIsInbounds();
212 return NewGEP;
209213 }
210214
211215
124124
125125 define i32* @test8({ i32, i32 } *%A, i1 %b) {
126126 BB0:
127 %X = getelementptr { i32, i32 } *%A, i32 0, i32 1
127 %X = getelementptr inbounds { i32, i32 } *%A, i32 0, i32 1
128128 br i1 %b, label %BB1, label %BB2
129129
130130 BB1:
138138 ; CHECK: @test8
139139 ; CHECK-NOT: phi
140140 ; CHECK: BB2:
141 ; CHECK-NEXT: %B = getelementptr
141 ; CHECK-NEXT: %B = getelementptr %0
142142 ; CHECK-NEXT: ret i32* %B
143143 }
144144
524524 ; CHECK: Exit:
525525 ; CHECK-NEXT: ret i32 %B
526526 }
527