[llvm] [InstCombine] Fold icmp(constants[x]) when the range of x is given (PR #67093)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 29 01:32:39 PST 2023


================
@@ -394,13 +409,15 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
     // Look for an appropriate type:
     // - The type of Idx if the magic fits
     // - The smallest fitting legal type
-    if (ArrayElementCount <= Idx->getType()->getIntegerBitWidth())
-      Ty = Idx->getType();
+
+    if (ElementCountToTraverse <= PtrIdxTy->getIntegerBitWidth())
+      Ty = PtrIdxTy;
     else
-      Ty = DL.getSmallestLegalIntType(Init->getContext(), ArrayElementCount);
+      Ty = DL.getSmallestLegalIntType(Init->getContext(),
+                                      ElementCountToTraverse);
 
     if (Ty) {
-      Idx = MaskIdx(Idx);
+      Idx = LazyGetIndex(Idx);
       Value *V = Builder.CreateIntCast(Idx, Ty, false);
       V = Builder.CreateLShr(ConstantInt::get(Ty, MagicBitvector), V);
       V = Builder.CreateAnd(ConstantInt::get(Ty, 1), V);
----------------
dtcxzyw wrote:

Please avoid creating multiple instructions when the load has multiple users.
See also https://github.com/dtcxzyw/llvm-opt-benchmark/pull/28/files/f845e103a2e2a78409e1f2aed9e21733056fd134#r1435245448.
But it would be good to do it in a separate PR.


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


More information about the llvm-commits mailing list