[llvm] LAA: improve code in getStrideFromPointer (NFC) (PR #124780)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 06:37:41 PST 2025


================
@@ -2888,25 +2885,19 @@ static const SCEV *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *L
     return nullptr;
 
   V = S->getStepRecurrence(*SE);
-  if (!V)
-    return nullptr;
 
   // Strip off the size of access multiplication if we are still analyzing the
   // pointer.
   if (OrigPtr == Ptr) {
-    if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(V)) {
-      if (M->getOperand(0)->getSCEVType() != scConstant)
+    if (auto *M = dyn_cast<SCEVMulExpr>(V)) {
+      auto *StepConst = dyn_cast<SCEVConstant>(M->getOperand(0));
+      if (!StepConst)
         return nullptr;
 
-      const APInt &APStepVal = cast<SCEVConstant>(M->getOperand(0))->getAPInt();
-
-      // Huge step value - give up.
-      if (APStepVal.getBitWidth() > 64)
+      auto StepVal = StepConst->getAPInt().trySExtValue();
+      if (!StepVal || StepVal != 1)
----------------
fhahn wrote:

Can we either keep and move the named variable `PtrAccessSize` here instead of checking for `1` or add a comment explaining why we are checking for 1?

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


More information about the llvm-commits mailing list