-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LAA] Fix non-NFC parts of 1aded51 #160701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1aded51 ([LAA] Prepare to handle diff type sizes (NFC)) was supposed to be a non-functional patch, but introduced functional changes as known-non-negative and known-non-positive is not equivalent to !known-non-zero. Fix this.
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) Changes1aded51 ([LAA] Prepare to handle diff type sizes (NFC)) was supposed to be a non-functional patch, but introduced functional changes as known-non-negative and known-non-positive is not equivalent to !known-non-zero. Fix this. Full diff: https://github.com/llvm/llvm-project/pull/160701.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index d6ad855cad9a7..512ae415d1c3b 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2122,7 +2122,8 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
// dependence.
TypeSize AStoreSz = DL.getTypeStoreSize(ATy);
TypeSize BStoreSz = DL.getTypeStoreSize(BTy);
- if (AStoreSz != BStoreSz && !SE.isKnownNonZero(Dist)) {
+ if (AStoreSz != BStoreSz && SE.isKnownNonPositive(Dist) &&
+ SE.isKnownNonNegative(Dist)) {
LLVM_DEBUG(dbgs() << "LAA: possibly zero dependence distance with "
"different type sizes\n");
return Dependence::Unknown;
diff --git a/llvm/test/Analysis/LoopAccessAnalysis/depend_diff_types.ll b/llvm/test/Analysis/LoopAccessAnalysis/depend_diff_types.ll
index 023a8c056968f..c367b31f6d445 100644
--- a/llvm/test/Analysis/LoopAccessAnalysis/depend_diff_types.ll
+++ b/llvm/test/Analysis/LoopAccessAnalysis/depend_diff_types.ll
@@ -187,6 +187,45 @@ exit:
ret void
}
+; In the following test, dependence distance is possibly zero,
+; but this is not equivalent to the condition known-non-positive
+; and known-non-negative.
+
+define void @possibly_zero_dist_diff_typesz(ptr %p) {
+; CHECK-LABEL: 'possibly_zero_dist_diff_typesz'
+; CHECK-NEXT: loop:
+; CHECK-NEXT: Memory dependences are safe
+; CHECK-NEXT: Dependences:
+; CHECK-NEXT: Forward:
+; CHECK-NEXT: %ld.p = load i32, ptr %gep.p.iv.i32, align 1 ->
+; CHECK-NEXT: store i16 %trunc, ptr %gep.p.iv.i16, 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:
+ %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop ]
+ %gep.p.iv.i32 = getelementptr inbounds nuw i32, ptr %p, i16 %iv
+ %ld.p = load i32, ptr %gep.p.iv.i32, align 1
+ %trunc = trunc i32 %ld.p to i16
+ %gep.p.iv.i16 = getelementptr inbounds nuw i16, ptr %p, i16 %iv
+ store i16 %trunc, ptr %gep.p.iv.i16, align 1
+ %iv.next = add nuw nsw i16 %iv, 1
+ %exit.cond = icmp eq i16 %iv.next, 32
+ br i1 %exit.cond, label %exit, label %loop
+
+exit:
+ ret void
+}
+
; In the following test, the sink is loop-invariant.
define void @type_size_equivalence_sink_loopinv(ptr nocapture %vec, i64 %n) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I tried to find a nicer way to check SCEV for zero and found this in ScalarEvolution.cpp:
const SCEV *Zero = SE.getZero(B->getType());
if (!SE.isKnownPredicate(CmpInst::ICMP_EQ, URem, Zero))
But I am not sure we need the strength behind isKnownPredicate
and it may become non-NFC again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Interestign that it's needed
Thank you! This does seem to fix the regressions we saw. |
Hi again @artagnon After some more testing we see that the following starts crashing with this patch and it still crashes on trunk (d48bda5):
|
Thanks again for the subtle bug report with if (!LoopGuards)
LoopGuards.emplace(
ScalarEvolution::LoopGuards::collect(InnermostLoop, SE));
Dist = SE.applyLoopGuards(Dist, *LoopGuards); Will fix in the morning. |
We are starting to see the same assertion failure in our builders at Google.
|
@artagnon -- Is it alright to land a revert to unblock our builders with weekend approaching? |
1aded51 ([LAA] Prepare to handle diff type sizes (NFC)) was supposed to be a non-functional patch, but introduced functional changes as known-non-negative and known-non-positive is not equivalent to !known-non-zero. Fix this.
1aded51 ([LAA] Prepare to handle diff type sizes (NFC)) was supposed to be a non-functional patch, but introduced functional changes as known-non-negative and known-non-positive is not equivalent to !known-non-zero. Fix this.