[llvm] [LAA] Strip dead code in getStrideFromPointer (NFC) (PR #139140)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 13:04:59 PDT 2025


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/139140

The SCEV multiply by 1 doesn't make sense, because SCEV would fold it: therefore, the OrigPtr == Ptr branch effectively rejects a multiply. However, in this branch, we have a pointer SCEV that cannot be a multiply, and hence the code the code is dead. Strip it.

>From ddc4d94326f677f4568921d6a4cde04a99a1b78b Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Thu, 8 May 2025 21:00:25 +0100
Subject: [PATCH] [LAA] Strip dead code in getStrideFromPointer (NFC)

The SCEV multiply by 1 doesn't make sense, because SCEV would fold it:
therefore, the OrigPtr == Ptr branch effectively rejects a multiply.
However, in this branch, we have a pointer SCEV that cannot be a
multiply, and hence the code the code is dead. Strip it.
---
 llvm/lib/Analysis/LoopAccessAnalysis.cpp | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index f222a9905c3bb..1f9cf8de34283 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2862,23 +2862,6 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
 
   V = S->getStepRecurrence(*SE);
 
-  // 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);
-    }
-  }
-
   // Note that the restriction after this loop invariant check are only
   // profitability restrictions.
   if (!SE->isLoopInvariant(V, Lp))



More information about the llvm-commits mailing list