Skip to content

Commit 234cc40

Browse files
committed
[LAA] Limit no-overlap check to at least one loop-invariant accesses.
Limit the logic added in #9230 to cases where either sink or source are loop-invariant, to avoid compile-time increases. This is not needed for correctness. I am working on follow-up changes to reduce the compile-time impact in general to allow us to enable this again for any source/sink. This should fix the compile-time regression introduced by this change: * compile-time improvement with this change: https://llvm-compile-time-tracker.com/compare.php?from=4351787fb650da6d1bfb8d6e58753c90dcd4c418&to=b89010a2eb5f98494787c1c3b77f25208c59090c&stat=instructions:u * compile-time improvement with original patch reverted on top of this change: https://llvm-compile-time-tracker.com/compare.php?from=b89010a2eb5f98494787c1c3b77f25208c59090c&to=19a1103fe68115cfd7d6472c6961f4fabe81a593&stat=instructions:u
1 parent 259caad commit 234cc40

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,20 +1983,25 @@ getDependenceDistanceStrideAndSize(
19831983
return MemoryDepChecker::Dependence::IndirectUnsafe;
19841984

19851985
// Check if we can prove that Sink only accesses memory after Src's end or
1986-
// vice versa.
1987-
const auto &[SrcStart, SrcEnd] =
1988-
getStartAndEndForAccess(InnermostLoop, Src, ATy, PSE);
1989-
const auto &[SinkStart, SinkEnd] =
1990-
getStartAndEndForAccess(InnermostLoop, Sink, BTy, PSE);
1991-
1992-
if (!isa<SCEVCouldNotCompute>(SrcStart) &&
1993-
!isa<SCEVCouldNotCompute>(SrcEnd) &&
1994-
!isa<SCEVCouldNotCompute>(SinkStart) &&
1995-
!isa<SCEVCouldNotCompute>(SinkEnd)) {
1996-
if (SE.isKnownPredicate(CmpInst::ICMP_ULE, SrcEnd, SinkStart))
1997-
return MemoryDepChecker::Dependence::NoDep;
1998-
if (SE.isKnownPredicate(CmpInst::ICMP_ULE, SinkEnd, SrcStart))
1999-
return MemoryDepChecker::Dependence::NoDep;
1986+
// vice versa. At the moment this is limited to cases where either source or
1987+
// sink are loop invariant to avoid compile-time increases. This is not
1988+
// required for correctness.
1989+
if (SE.isLoopInvariant(Src, InnermostLoop) ||
1990+
SE.isLoopInvariant(Sink, InnermostLoop)) {
1991+
const auto &[SrcStart, SrcEnd] =
1992+
getStartAndEndForAccess(InnermostLoop, Src, ATy, PSE);
1993+
const auto &[SinkStart, SinkEnd] =
1994+
getStartAndEndForAccess(InnermostLoop, Sink, BTy, PSE);
1995+
1996+
if (!isa<SCEVCouldNotCompute>(SrcStart) &&
1997+
!isa<SCEVCouldNotCompute>(SrcEnd) &&
1998+
!isa<SCEVCouldNotCompute>(SinkStart) &&
1999+
!isa<SCEVCouldNotCompute>(SinkEnd)) {
2000+
if (SE.isKnownPredicate(CmpInst::ICMP_ULE, SrcEnd, SinkStart))
2001+
return MemoryDepChecker::Dependence::NoDep;
2002+
if (SE.isKnownPredicate(CmpInst::ICMP_ULE, SinkEnd, SrcStart))
2003+
return MemoryDepChecker::Dependence::NoDep;
2004+
}
20002005
}
20012006

20022007
// Need accesses with constant strides and the same direction. We don't want

llvm/test/Analysis/LoopAccessAnalysis/depend_diff_types.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,16 @@ define void @neg_dist_dep_type_size_equivalence(ptr nocapture %vec, i64 %n) {
130130
; CHECK-LABEL: 'neg_dist_dep_type_size_equivalence'
131131
; CHECK-NEXT: loop:
132132
; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop
133-
; CHECK-NEXT: Backward loop carried data dependence that prevents store-to-load forwarding.
133+
; CHECK-NEXT: Unknown data dependence.
134134
; CHECK-NEXT: Dependences:
135+
; CHECK-NEXT: Unknown:
136+
; CHECK-NEXT: %ld.f64 = load double, ptr %gep.iv, align 8 ->
137+
; CHECK-NEXT: store i32 %ld.i64.i32, ptr %gep.iv.n.i64, align 8
138+
; CHECK-EMPTY:
139+
; CHECK-NEXT: Unknown:
140+
; CHECK-NEXT: %ld.i64 = load i64, ptr %gep.iv, align 8 ->
141+
; CHECK-NEXT: store i32 %ld.i64.i32, ptr %gep.iv.n.i64, align 8
142+
; CHECK-EMPTY:
135143
; CHECK-NEXT: BackwardVectorizableButPreventsForwarding:
136144
; CHECK-NEXT: %ld.f64 = load double, ptr %gep.iv, align 8 ->
137145
; CHECK-NEXT: store double %val, ptr %gep.iv.101.i64, align 8

llvm/test/Analysis/LoopAccessAnalysis/non-constant-strides-backward.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ exit:
4545
define void @different_non_constant_strides_known_backward_distance_larger_than_trip_count(ptr %A) {
4646
; CHECK-LABEL: 'different_non_constant_strides_known_backward_distance_larger_than_trip_count'
4747
; CHECK-NEXT: loop:
48-
; CHECK-NEXT: Memory dependences are safe
48+
; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop
49+
; CHECK-NEXT: Unknown data dependence.
4950
; CHECK-NEXT: Dependences:
51+
; CHECK-NEXT: Unknown:
52+
; CHECK-NEXT: %l = load i32, ptr %gep, align 4 ->
53+
; CHECK-NEXT: store i32 %add, ptr %gep.mul.2, align 4
54+
; CHECK-EMPTY:
5055
; CHECK-NEXT: Run-time memory checks:
5156
; CHECK-NEXT: Grouped accesses:
5257
; CHECK-EMPTY:

0 commit comments

Comments
 (0)