[llvm] [InstCombine] Fold icmp(constants[x]) when the range of x is given (PR #67093)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 23 10:22:31 PST 2023
================
@@ -187,43 +167,58 @@ 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));
+ // The longest step we can reach once.
+ APInt OffsetStep = VariableOffsets.front().second;
+
+ // BeginOffset is the offset from constant pointer where we begin scanning the
+ // constant. Make BeginOffset the smallest offset greater than 0
+ APInt BeginOffset = ConstantOffset.srem(OffsetStep);
+ if (BeginOffset.slt(0))
+ BeginOffset += OffsetStep;
+
+ uint64_t ElementCountToTraverse = (DataSize - BeginOffset).udiv(OffsetStep).getZExtValue() + 1;
----------------
XChy wrote:
I missed "+1" here, actually `BeginOffset` indeed includes one more element. Fix it now.
https://github.com/llvm/llvm-project/pull/67093
More information about the llvm-commits
mailing list