Skip to content

Commit 9cf1881

Browse files
committed
[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
1 parent fd527ce commit 9cf1881

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,11 @@ static Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp) {
26422642
if (!S)
26432643
return nullptr;
26442644

2645+
// If the pointer is invariant then there is no stride and it makes no
2646+
// sense to add it here.
2647+
if (Lp != S->getLoop())
2648+
return nullptr;
2649+
26452650
V = S->getStepRecurrence(*SE);
26462651
if (!V)
26472652
return nullptr;

llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
define void @foo(ptr %pout, ptr %pin, i64 %val0, i64 %val1, i64 %val2) {
77
; CHECK-LABEL: @foo(
8-
; FIXME: CHECK below needs to be changed to CHECK-NOT to confirm the change.
9-
; CHECK: vector.scevcheck
8+
; CHECK-NOT: vector.scevcheck
109
; CHECK: vector.body
1110
entry:
1211
%0 = getelementptr double, ptr %pin, i64 %val0
@@ -45,8 +44,7 @@ exit: ; preds = %loop1.latch
4544

4645
define void @bar(ptr %pout, ptr %pin, i64 %val0, i64 %val1, i64 %val2) {
4746
; CHECK-LABEL: @bar(
48-
; FIXME: CHECK below needs to be changed to CHECK-NOT to confirm the change.
49-
; CHECK: vector.scevcheck
47+
; CHECK-NOT: vector.scevcheck
5048
; CHECK: vector.body
5149
entry:
5250
%0 = getelementptr double, ptr %pin, i64 %val0

0 commit comments

Comments
 (0)