[llvm] [SCEVPatternMatch] Extend with more matchers (PR #138836)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 12:51:17 PDT 2025
================
@@ -2864,20 +2863,8 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
// Strip off the size of access multiplication if we are still analyzing the
// pointer.
- if (OrigPtr == Ptr) {
- if (auto *M = dyn_cast<SCEVMulExpr>(V)) {
- auto *StepConst = dyn_cast<SCEVConstant>(M->getOperand(0));
- if (!StepConst)
- return nullptr;
-
- auto StepVal = StepConst->getAPInt().trySExtValue();
- // Bail out on a non-unit pointer access size.
- if (!StepVal || StepVal != 1)
- return nullptr;
-
- V = M->getOperand(1);
- }
- }
+ if (OrigPtr == Ptr)
+ match(V, m_scev_Mul(m_scev_SpecificInt(1), m_SCEV(V)));
----------------
nikic wrote:
So, this code is very weird. Your new code is never going to match anything, because a `1 * V` SCEV would fold to `V` at construction. What the old code did was effectively just reject any multiply, but... I think the old code was effectively dead because in the `OrigPtr == Ptr` case we're working on a pointer SCEV rather than an index, and a pointer SCEV cannot be multiplied.
So I think the correct thing to do would be to remove this entire if block. But we should do that in a separate change, not as part of this one.
https://github.com/llvm/llvm-project/pull/138836
More information about the llvm-commits
mailing list