Skip to content

Commit 22afcf6

Browse files
committed
!fixup address comments, thanks!
1 parent 112223d commit 22afcf6

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,28 +1796,28 @@ void MemoryDepChecker::mergeInStatus(VectorizationSafetyStatus S) {
17961796
/// Given a dependence-distance \p Dist between two
17971797
/// memory accesses, that have strides in the same direction whose absolute
17981798
/// value of the maximum stride is given in \p MaxStride, and that have the same
1799-
/// type size \p TypeByteSize, in a loop whose takenCount is \p
1800-
/// BackedgeTakenCount, check if it is possible to prove statically that the
1801-
/// dependence distance is larger than the range that the accesses will travel
1802-
/// through the execution of the loop. If so, return true; false otherwise. This
1803-
/// is useful for example in loops such as the following (PR31098):
1799+
/// type size \p TypeByteSize, in a loop whose maximum backedge taken count is
1800+
/// \p MaxBTC, check if it is possible to prove statically that the dependence
1801+
/// distance is larger than the range that the accesses will travel through the
1802+
/// execution of the loop. If so, return true; false otherwise. This is useful
1803+
/// for example in loops such as the following (PR31098):
18041804
/// for (i = 0; i < D; ++i) {
18051805
/// = out[i];
18061806
/// out[i+D] =
18071807
/// }
18081808
static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
1809-
const SCEV &BackedgeTakenCount,
1810-
const SCEV &Dist, uint64_t MaxStride,
1809+
const SCEV &MaxBTC, const SCEV &Dist,
1810+
uint64_t MaxStride,
18111811
uint64_t TypeByteSize) {
18121812

18131813
// If we can prove that
1814-
// (**) |Dist| > BackedgeTakenCount * Step
1814+
// (**) |Dist| > MaxBTC * Step
18151815
// where Step is the absolute stride of the memory accesses in bytes,
18161816
// then there is no dependence.
18171817
//
18181818
// Rationale:
18191819
// We basically want to check if the absolute distance (|Dist/Step|)
1820-
// is >= the loop iteration count (or > BackedgeTakenCount).
1820+
// is >= the loop iteration count (or > MaxBTC).
18211821
// This is equivalent to the Strong SIV Test (Practical Dependence Testing,
18221822
// Section 4.2.1); Note, that for vectorization it is sufficient to prove
18231823
// that the dependence distance is >= VF; This is checked elsewhere.
@@ -1828,8 +1828,8 @@ static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
18281828
// also guarantees that distance >= VF.
18291829
//
18301830
const uint64_t ByteStride = MaxStride * TypeByteSize;
1831-
const SCEV *Step = SE.getConstant(BackedgeTakenCount.getType(), ByteStride);
1832-
const SCEV *Product = SE.getMulExpr(&BackedgeTakenCount, Step);
1831+
const SCEV *Step = SE.getConstant(MaxBTC.getType(), ByteStride);
1832+
const SCEV *Product = SE.getMulExpr(&MaxBTC, Step);
18331833

18341834
const SCEV *CastedDist = &Dist;
18351835
const SCEV *CastedProduct = Product;
@@ -1844,13 +1844,13 @@ static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
18441844
else
18451845
CastedDist = SE.getNoopOrSignExtend(&Dist, Product->getType());
18461846

1847-
// Is Dist - (BackedgeTakenCount * Step) > 0 ?
1847+
// Is Dist - (MaxBTC * Step) > 0 ?
18481848
// (If so, then we have proven (**) because |Dist| >= Dist)
18491849
const SCEV *Minus = SE.getMinusSCEV(CastedDist, CastedProduct);
18501850
if (SE.isKnownPositive(Minus))
18511851
return true;
18521852

1853-
// Second try: Is -Dist - (BackedgeTakenCount * Step) > 0 ?
1853+
// Second try: Is -Dist - (MaxBTC * Step) > 0 ?
18541854
// (If so, then we have proven (**) because |Dist| >= -1*Dist)
18551855
const SCEV *NegDist = SE.getNegativeSCEV(CastedDist);
18561856
Minus = SE.getMinusSCEV(NegDist, CastedProduct);
@@ -2057,9 +2057,10 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
20572057
uint64_t MaxStride = std::max(StrideA, StrideB);
20582058

20592059
// If the distance between the acecsses is larger than their maximum absolute
2060-
// stride multiplied by the backedge taken count, the accesses are independet,
2061-
// i.e. they are far enough appart that accesses won't access the same
2062-
// location across all loop ierations.
2060+
// stride multiplied by the symbolic maximum backedge taken count (which is an
2061+
// upper bound of the number of iterations), the accesses are independet, i.e.
2062+
// they are far enough appart that accesses won't access the same location
2063+
// across all loop ierations.
20632064
if (HasSameSize && isSafeDependenceDistance(
20642065
DL, SE, *(PSE.getSymbolicMaxBackedgeTakenCount()),
20652066
*Dist, MaxStride, TypeByteSize))
@@ -2399,7 +2400,9 @@ bool LoopAccessInfo::canAnalyzeLoop() {
23992400
return false;
24002401
}
24012402

2402-
// ScalarEvolution needs to be able to find the exit count.
2403+
// ScalarEvolution needs to be able to find the symbolic max backedge taken
2404+
// count, which is an upper bound on the number of loop iterations. The loop
2405+
// may execute fewer iterations, if it exits via an uncountable exit.
24032406
const SCEV *ExitCount = PSE->getSymbolicMaxBackedgeTakenCount();
24042407
if (isa<SCEVCouldNotCompute>(ExitCount)) {
24052408
recordAnalysis("CantComputeNumberOfIterations")
@@ -3009,25 +3012,25 @@ void LoopAccessInfo::collectStridedAccess(Value *MemAccess) {
30093012
// of various possible stride specializations, considering the alternatives
30103013
// of using gather/scatters (if available).
30113014

3012-
const SCEV *BETakenCount = PSE->getSymbolicMaxBackedgeTakenCount();
3015+
const SCEV *MaxBTC = PSE->getSymbolicMaxBackedgeTakenCount();
30133016

3014-
// Match the types so we can compare the stride and the BETakenCount.
3017+
// Match the types so we can compare the stride and the MaxBTC.
30153018
// The Stride can be positive/negative, so we sign extend Stride;
3016-
// The backedgeTakenCount is non-negative, so we zero extend BETakenCount.
3019+
// The backedgeTakenCount is non-negative, so we zero extend MaxBTC.
30173020
const DataLayout &DL = TheLoop->getHeader()->getModule()->getDataLayout();
30183021
uint64_t StrideTypeSizeBits = DL.getTypeSizeInBits(StrideExpr->getType());
3019-
uint64_t BETypeSizeBits = DL.getTypeSizeInBits(BETakenCount->getType());
3022+
uint64_t BETypeSizeBits = DL.getTypeSizeInBits(MaxBTC->getType());
30203023
const SCEV *CastedStride = StrideExpr;
3021-
const SCEV *CastedBECount = BETakenCount;
3024+
const SCEV *CastedBECount = MaxBTC;
30223025
ScalarEvolution *SE = PSE->getSE();
30233026
if (BETypeSizeBits >= StrideTypeSizeBits)
3024-
CastedStride = SE->getNoopOrSignExtend(StrideExpr, BETakenCount->getType());
3027+
CastedStride = SE->getNoopOrSignExtend(StrideExpr, MaxBTC->getType());
30253028
else
3026-
CastedBECount = SE->getZeroExtendExpr(BETakenCount, StrideExpr->getType());
3029+
CastedBECount = SE->getZeroExtendExpr(MaxBTC, StrideExpr->getType());
30273030
const SCEV *StrideMinusBETaken = SE->getMinusSCEV(CastedStride, CastedBECount);
30283031
// Since TripCount == BackEdgeTakenCount + 1, checking:
30293032
// "Stride >= TripCount" is equivalent to checking:
3030-
// Stride - BETakenCount > 0
3033+
// Stride - MaxBTC> 0
30313034
if (SE->isKnownPositive(StrideMinusBETaken)) {
30323035
LLVM_DEBUG(
30333036
dbgs() << "LAA: Stride>=TripCount; No point in versioning as the "

llvm/test/Analysis/LoopAccessAnalysis/memcheck-wrapping-pointers.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
2929
; CHECK-NEXT: Run-time memory checks:
3030
; CHECK-NEXT: Check 0:
3131
; CHECK-NEXT: Comparing group
32-
; CHECK-NEXT: %arrayidx4 = getelementptr inbounds i32, ptr %b, i64 %conv11
33-
; CHECK-NEXT: Against group
3432
; CHECK-NEXT: %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom
33+
; CHECK-NEXT: Against group
34+
; CHECK-NEXT: %arrayidx4 = getelementptr inbounds i32, ptr %b, i64 %conv11
3535
; CHECK-NEXT: Grouped accesses:
3636
; CHECK-NEXT: Group
37-
; CHECK-NEXT: (Low: %b High: ((4 * (1 umax %x)) + %b))
38-
; CHECK-NEXT: Member: {%b,+,4}<%for.body>
39-
; CHECK-NEXT: Group
4037
; CHECK-NEXT: (Low: (4 + %a) High: (4 + (4 * (1 umax %x)) + %a))
4138
; CHECK-NEXT: Member: {(4 + %a),+,4}<%for.body>
39+
; CHECK-NEXT: Group
40+
; CHECK-NEXT: (Low: %b High: ((4 * (1 umax %x)) + %b))
41+
; CHECK-NEXT: Member: {%b,+,4}<%for.body>
4242
; CHECK: Non vectorizable stores to invariant address were not found in loop.
4343
; CHECK-NEXT: SCEV assumptions:
44-
; CHECK-NEXT: {0,+,1}<%for.body> Added Flags: <nusw>
4544
; CHECK-NEXT: {1,+,1}<%for.body> Added Flags: <nusw>
45+
; CHECK-NEXT: {0,+,1}<%for.body> Added Flags: <nusw>
4646
; CHECK: Expressions re-written:
4747
; CHECK-NEXT: [PSE] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %idxprom:
4848
; CHECK-NEXT: ((4 * (zext i32 {1,+,1}<%for.body> to i64))<nuw><nsw> + %a)<nuw>
@@ -84,8 +84,8 @@ exit:
8484
; CHECK-LABEL: test2
8585
; CHECK: Memory dependences are safe
8686
; CHECK: SCEV assumptions:
87-
; CHECK-NEXT: {0,+,1}<%for.body> Added Flags: <nusw>
8887
; CHECK-NEXT: {1,+,1}<%for.body> Added Flags: <nusw>
88+
; CHECK-NEXT: {0,+,1}<%for.body> Added Flags: <nusw>
8989
define void @test2(i64 %x, ptr %a) {
9090
entry:
9191
br label %for.body

llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
; YAML-NEXT: - String: 'loop not vectorized: '
125125
; YAML-NEXT: - String: could not determine number of loop iterations
126126
; YAML-NEXT: ...
127-
; YAML-NEXT: --- !Missed
127+
; YAML: --- !Missed
128128
; YAML-NEXT: Pass: loop-vectorize
129129
; YAML-NEXT: Name: MissedDetails
130130
; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }

0 commit comments

Comments
 (0)