[llvm] 17139f3 - [LAA] Check HasSameSize before couldPreventStoreLoadForward.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 02:10:49 PST 2023
Author: Florian Hahn
Date: 2023-11-27T10:10:41Z
New Revision: 17139f38e55ec06b8546b9306e04e64d0408033a
URL: https://github.com/llvm/llvm-project/commit/17139f38e55ec06b8546b9306e04e64d0408033a
DIFF: https://github.com/llvm/llvm-project/commit/17139f38e55ec06b8546b9306e04e64d0408033a.diff
LOG: [LAA] Check HasSameSize before couldPreventStoreLoadForward.
After 9645267, TypeByteSize is 0 if both access do not have the same
size (i.e. HasSameSize will be false). This can cause an infinite loop
in couldPreventStoreLoadForward, if HasSameSize is not checked first.
So check HasSameSize first instead of after
couldPreventStoreLoadForward. Checking HasSameSize first is also
cheaper.
Added:
Modified:
llvm/lib/Analysis/LoopAccessAnalysis.cpp
llvm/test/Analysis/LoopAccessAnalysis/forward-loop-carried.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 999af560f1fd8c0..91f5eab03b032ce 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2009,8 +2009,8 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
// couldPreventStoreLoadForward, even if it changed MinDepDistBytes,
// since a forward dependency will allow vectorization using any width.
if (IsTrueDataDependence && EnableForwardingConflictDetection &&
- (couldPreventStoreLoadForward(Val.abs().getZExtValue(), TypeByteSize) ||
- !HasSameSize)) {
+ (!HasSameSize || couldPreventStoreLoadForward(Val.abs().getZExtValue(),
+ TypeByteSize))) {
LLVM_DEBUG(dbgs() << "LAA: Forward but may prevent st->ld forwarding\n");
return Dependence::ForwardButPreventsForwarding;
}
diff --git a/llvm/test/Analysis/LoopAccessAnalysis/forward-loop-carried.ll b/llvm/test/Analysis/LoopAccessAnalysis/forward-loop-carried.ll
index 2b5bad49da1efa7..adfd19923e921cd 100644
--- a/llvm/test/Analysis/LoopAccessAnalysis/forward-loop-carried.ll
+++ b/llvm/test/Analysis/LoopAccessAnalysis/forward-loop-carried.ll
@@ -53,3 +53,49 @@ for.body: ; preds = %for.body, %entry
for.end: ; preds = %for.body
ret void
}
+
+%struct = type { i8, [3 x i8], i32 }
+
+define void @forward_
diff erent_access_sizes(ptr readnone %end, ptr %start) {
+; CHECK-LABEL: 'forward_
diff erent_access_sizes'
+; CHECK-NEXT: loop:
+; 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
+; CHECK-NEXT: Forward loop carried data dependence that prevents store-to-load forwarding.
+; CHECK-NEXT: Dependences:
+; CHECK-NEXT: Forward:
+; CHECK-NEXT: %l = load i24, ptr %gep.1, align 1 ->
+; CHECK-NEXT: store i24 %l, ptr %ptr.iv, align 1
+; CHECK-EMPTY:
+; CHECK-NEXT: ForwardButPreventsForwarding:
+; CHECK-NEXT: store i32 0, ptr %gep.2, align 4 ->
+; CHECK-NEXT: %l = load i24, ptr %gep.1, align 1
+; CHECK-EMPTY:
+; CHECK-NEXT: Forward:
+; CHECK-NEXT: store i32 0, ptr %gep.2, align 4 ->
+; CHECK-NEXT: store i24 %l, ptr %ptr.iv, align 1
+; CHECK-EMPTY:
+; CHECK-NEXT: Run-time memory checks:
+; CHECK-NEXT: Grouped accesses:
+; CHECK-EMPTY:
+; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.
+; CHECK-NEXT: SCEV assumptions:
+; CHECK-EMPTY:
+; CHECK-NEXT: Expressions re-written:
+;
+entry:
+ br label %loop
+
+loop:
+ %ptr.iv = phi ptr [ %start, %entry ], [ %next, %loop ]
+ %gep.2 = getelementptr %struct, ptr %ptr.iv, i64 0, i32 2
+ store i32 0, ptr %gep.2, align 4
+ %gep.1 = getelementptr %struct, ptr %ptr.iv, i64 0, i32 1
+ %l = load i24, ptr %gep.1, align 1
+ store i24 %l, ptr %ptr.iv, align 1
+ %next = getelementptr inbounds %struct, ptr %ptr.iv, i64 1
+ %ec = icmp eq ptr %ptr.iv, %end
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list