[llvm] [InstCombine] Don't handle non-canonical index type in icmp of load fold (PR #151346)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 30 08:34:14 PDT 2025


================
@@ -290,17 +295,6 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
 
   // Now that we've scanned the entire array, emit our new comparison(s).  We
   // order the state machines in complexity of the generated code.
-  Value *Idx = GEP->getOperand(2);
-
-  // If the index is larger than the pointer offset size of the target, truncate
-  // the index down like the GEP would do implicitly.  We don't have to do this
-  // for an inbounds GEP because the index can't be out of range.
-  if (!GEP->isInBounds()) {
-    Type *PtrIdxTy = DL.getIndexType(GEP->getType());
-    unsigned OffsetSize = PtrIdxTy->getIntegerBitWidth();
-    if (Idx->getType()->getPrimitiveSizeInBits().getFixedValue() > OffsetSize)
-      Idx = Builder.CreateTrunc(Idx, PtrIdxTy);
----------------
dtcxzyw wrote:

It reminds me that we can add nsw/nuw to the trunc when canonicalizing the index type: https://alive2.llvm.org/ce/z/niXbox

https://github.com/llvm/llvm-project/pull/151346


More information about the llvm-commits mailing list