@@ -163,6 +163,11 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
163
163
LaterIndices.push_back (IdxVal);
164
164
}
165
165
166
+ Value *Idx = GEP->getOperand (2 );
167
+ // If the index type is non-canonical, wait for it to be canonicalized.
168
+ if (Idx->getType () != DL.getIndexType (GEP->getType ()))
169
+ return nullptr ;
170
+
166
171
enum { Overdefined = -3 , Undefined = -2 };
167
172
168
173
// Variables for our state machines.
@@ -290,17 +295,6 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
290
295
291
296
// Now that we've scanned the entire array, emit our new comparison(s). We
292
297
// order the state machines in complexity of the generated code.
293
- Value *Idx = GEP->getOperand (2 );
294
-
295
- // If the index is larger than the pointer offset size of the target, truncate
296
- // the index down like the GEP would do implicitly. We don't have to do this
297
- // for an inbounds GEP because the index can't be out of range.
298
- if (!GEP->isInBounds ()) {
299
- Type *PtrIdxTy = DL.getIndexType (GEP->getType ());
300
- unsigned OffsetSize = PtrIdxTy->getIntegerBitWidth ();
301
- if (Idx->getType ()->getPrimitiveSizeInBits ().getFixedValue () > OffsetSize)
302
- Idx = Builder.CreateTrunc (Idx, PtrIdxTy);
303
- }
304
298
305
299
// If inbounds keyword is not present, Idx * ElementSize can overflow.
306
300
// Let's assume that ElementSize is 2 and the wanted value is at offset 0.
0 commit comments