@@ -163,6 +163,11 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
163163 LaterIndices.push_back (IdxVal);
164164 }
165165
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+
166171 enum { Overdefined = -3 , Undefined = -2 };
167172
168173 // Variables for our state machines.
@@ -290,17 +295,6 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
290295
291296 // Now that we've scanned the entire array, emit our new comparison(s). We
292297 // 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- }
304298
305299 // If inbounds keyword is not present, Idx * ElementSize can overflow.
306300 // Let's assume that ElementSize is 2 and the wanted value is at offset 0.
0 commit comments