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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 04:02:26 PST 2023


================
@@ -187,18 +168,36 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
   // the array, this will fully represent all the comparison results.
   uint64_t MagicBitvector = 0;
 
+  Value *Idx = nullptr;
+
   // Scan the array and see if one of our patterns matches.
-  Constant *CompareRHS = cast<Constant>(ICI.getOperand(1));
-  for (unsigned i = 0, e = ArrayElementCount; i != e; ++i) {
-    Constant *Elt = Init->getAggregateElement(i);
-    if (!Elt) return nullptr;
-
-    // If this is indexing an array of structures, get the structure element.
-    if (!LaterIndices.empty()) {
-      Elt = ConstantFoldExtractValueInstruction(Elt, LaterIndices);
-      if (!Elt)
-        return nullptr;
-    }
+  Constant *ComparedRHS = cast<Constant>(ICI.getOperand(1));
+  APInt OffsetStep = VariableOffsets.front().second;
+  // The longest step we can reach once.
+  uint64_t OffsetStepZExt = OffsetStep.getZExtValue();
----------------
nikic wrote:

Why are we dropping out of APInt here? If we do this, we need to add a check that it fits in 64-bit.

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


More information about the llvm-commits mailing list