[llvm] 9cf1881 - [SCEV] Do not plant SCEV checks unnecessarily

Paul Osmialowski via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 13:47:51 PDT 2023


Author: Paul Osmialowski
Date: 2023-04-25T21:47:14+01:00
New Revision: 9cf1881f8f12a70c28432278a2878a6113c017c1

URL: https://github.com/llvm/llvm-project/commit/9cf1881f8f12a70c28432278a2878a6113c017c1
DIFF: https://github.com/llvm/llvm-project/commit/9cf1881f8f12a70c28432278a2878a6113c017c1.diff

LOG: [SCEV] Do not plant SCEV checks unnecessarily

The vectorisation analysis collects strides for loop invariant
pointers, which is wrong because they are not strided. We don't
need to generate SCEV checks (which are costly performancewise)
for such pointers, we just need to do the appropriate aliasing
checks.

This patch fixes the problem by changing getStrideFromPointer()
to treat loop invariant pointers as having no stride.

Originally proposed by David Sherwood with further suggestions
from Florian Hahn.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D146958

Added: 
    

Modified: 
    llvm/lib/Analysis/LoopAccessAnalysis.cpp
    llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 623cd22e3295..4420d729e288 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2642,6 +2642,11 @@ static Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
   if (!S)
     return nullptr;
 
+  // If the pointer is invariant then there is no stride and it makes no
+  // sense to add it here.
+  if (Lp != S->getLoop())
+    return nullptr;
+
   V = S->getStepRecurrence(*SE);
   if (!V)
     return nullptr;

diff  --git a/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll b/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll
index 3b37e1565f9d..60d782815915 100644
--- a/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll
+++ b/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll
@@ -5,8 +5,7 @@
 
 define void @foo(ptr %pout, ptr %pin, i64 %val0, i64 %val1, i64 %val2) {
 ; CHECK-LABEL: @foo(
-; FIXME: CHECK below needs to be changed to CHECK-NOT to confirm the change.
-; CHECK: vector.scevcheck
+; CHECK-NOT: vector.scevcheck
 ; CHECK: vector.body
 entry:
   %0 = getelementptr double, ptr %pin, i64 %val0
@@ -45,8 +44,7 @@ exit:                                             ; preds = %loop1.latch
 
 define void @bar(ptr %pout, ptr %pin, i64 %val0, i64 %val1, i64 %val2) {
 ; CHECK-LABEL: @bar(
-; FIXME: CHECK below needs to be changed to CHECK-NOT to confirm the change.
-; CHECK: vector.scevcheck
+; CHECK-NOT: vector.scevcheck
 ; CHECK: vector.body
 entry:
   %0 = getelementptr double, ptr %pin, i64 %val0


        


More information about the llvm-commits mailing list