Skip to content

Commit b2f2383

Browse files
committed
[SCEV][LV] Add Stride equal to one Predicate to enable strided access versioning
This commit enable the vectorization for the case from llvm#71517. float s172(int xa, int xb) { for (int i = xa - 1; i < 32000; i += xb) a[i] += b[i]; } By assuming the stride as one and generating the runtime checking to guard the vectorized loop, it seems the case can be vectorized.
1 parent 18fab95 commit b2f2383

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12778,10 +12778,23 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1277812778
// The positive stride case is the same as isKnownPositive(Stride) returning
1277912779
// true (original behavior of the function).
1278012780
//
12781-
if (PredicatedIV || !NoWrap || !loopIsFiniteByAssumption(L) ||
12781+
if (PredicatedIV || !loopIsFiniteByAssumption(L) ||
1278212782
!loopHasNoAbnormalExits(L))
1278312783
return getCouldNotCompute();
1278412784

12785+
// Adding Stride equal to one Predicate when there is no wrap flags.
12786+
// It might enable strided access versioning in LAA and calculate BECount
12787+
// with Stride = 1.
12788+
if (!NoWrap) {
12789+
if (AllowPredicates) {
12790+
const auto *One =
12791+
static_cast<const SCEVConstant *>(getOne(Stride->getType()));
12792+
Predicates.insert(getEqualPredicate(Stride, One));
12793+
Stride = One;
12794+
} else
12795+
return getCouldNotCompute();
12796+
}
12797+
1278512798
if (!isKnownNonZero(Stride)) {
1278612799
// If we have a step of zero, and RHS isn't invariant in L, we don't know
1278712800
// if it might eventually be greater than start and if so, on which

llvm/test/Transforms/LoopVectorize/version-mem-access.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ for.end:
9393
ret void
9494
}
9595

96+
; We can vectorize the loop by using stride = 1 to calculate iteration count
97+
; and generate the runtime check to guard the vectorized loop.
98+
9699
; CHECK-LABEL: s172
97-
; CHECK-NOT: vector.body
100+
; CHECK-DAG: icmp ne i32 %xb, 1
101+
; CHECK: vector.body
98102

99103
@b = global [32000 x float] zeroinitializer, align 64
100104
@a = global [32000 x float] zeroinitializer, align 64

0 commit comments

Comments
 (0)