[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:13:33 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();
+ // Offset from constant pointer where we begin scanning the constant.
+ int64_t BeginOffset = ConstantOffset.getSExtValue();
+
+ // Make BeginOffset the smallest offset >= 0
+ if (BeginOffset % OffsetStepZExt == 0)
+ BeginOffset = 0;
+ else if (BeginOffset < 0)
+ BeginOffset += (-BeginOffset / OffsetStepZExt + 1) * OffsetStepZExt;
+ else if (BeginOffset > 0)
+ BeginOffset -= (BeginOffset / OffsetStepZExt) * OffsetStepZExt;
----------------
XChy wrote:
Simplify it now.
https://github.com/llvm/llvm-project/pull/67093
More information about the llvm-commits
mailing list