[llvm] [LAA] Improve code in findForkedSCEVs (NFC) (PR #140384)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 02:17:52 PDT 2025


================
@@ -999,24 +999,17 @@ static void findForkedSCEVs(
       break;
     }
 
-    // Find the pointer type we need to extend to.
-    Type *IntPtrTy = SE->getEffectiveSCEVType(
-        SE->getSCEV(GEP->getPointerOperand())->getType());
-
-    // Find the size of the type being pointed to. We only have a single
-    // index term (guarded above) so we don't need to index into arrays or
-    // structures, just get the size of the scalar value.
-    const SCEV *Size = SE->getSizeOfExpr(IntPtrTy, SourceTy);
-
-    // Scale up the offsets by the size of the type, then add to the bases.
-    const SCEV *Scaled1 = SE->getMulExpr(
-        Size, SE->getTruncateOrSignExtend(get<0>(OffsetScevs[0]), IntPtrTy));
-    const SCEV *Scaled2 = SE->getMulExpr(
-        Size, SE->getTruncateOrSignExtend(get<0>(OffsetScevs[1]), IntPtrTy));
-    ScevList.emplace_back(SE->getAddExpr(get<0>(BaseScevs[0]), Scaled1),
-                          NeedsFreeze);
-    ScevList.emplace_back(SE->getAddExpr(get<0>(BaseScevs[1]), Scaled2),
-                          NeedsFreeze);
+    for (auto [B, O] : zip(BaseScevs, OffsetScevs)) {
+      const SCEV *Base = get<0>(B);
+      const SCEV *Offset = get<0>(O);
+
+      // Scale up the offsets by the size of the type, then add to the bases.
+      const SCEV *Scaled = SE->getTruncateOrSignExtend(
+          SE->getMulExpr(SE->getSizeOfExpr(Offset->getType(), SourceTy),
+                         Offset),
+          Base->getType());
----------------
david-arm wrote:

Agreed. This doesn't really look like a NFC change to me. Can you explain why you had to rearrange the operations? If it's necessary to rearrange the operations then I think it would be better done in a separate patch to keep this one NFC.

Also, can you add some more comments in the commit message explaining the reason for this patch? Is it purely about reducing lines of code? Or is this patch a requirement for a follow-on?

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


More information about the llvm-commits mailing list