Skip to content

Commit

Permalink
[SCEV] Do not plant SCEV checks unnecessarily
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pawosm-arm committed Apr 25, 2023
1 parent fd527ce commit 9cf1881
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cf1881

Please sign in to comment.