-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[ValueTracking] Handle not in dominating condition. #126423
Conversation
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-llvm-transforms Author: Andreas Jonson (andjo403) ChangesGeneral handling of not split out from #126414 proof: https://alive2.llvm.org/ce/z/FjJN8q Full diff: https://github.com/llvm/llvm-project/pull/126423.diff 3 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8a9ad55366ee703..6163d6453db3514 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -801,6 +801,9 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
if (auto *Cmp = dyn_cast<ICmpInst>(Cond))
computeKnownBitsFromICmpCond(V, Cmp, Known, SQ, Invert);
+
+ if (Depth < MaxAnalysisRecursionDepth && match(Cond, m_Not(m_Value(A))))
+ computeKnownBitsFromCond(V, A, Known, Depth + 1, SQ, !Invert);
}
void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
@@ -4934,6 +4937,11 @@ static void computeKnownFPClassFromCond(const Value *V, Value *Cond,
KnownFromContext);
return;
}
+ if (Depth < MaxAnalysisRecursionDepth && match(Cond, m_Not(m_Value(A)))) {
+ computeKnownFPClassFromCond(V, A, Depth + 1, !CondIsTrue, CxtI,
+ KnownFromContext);
+ return;
+ }
CmpPredicate Pred;
Value *LHS;
uint64_t ClassVal = 0;
@@ -10272,6 +10280,8 @@ void llvm::findValuesAffectedByCondition(
m_Value()))) {
// Handle patterns that computeKnownFPClass() support.
AddAffected(A);
+ } else if (match(V, m_Not(m_Value(X)))) {
+ Worklist.push_back(X);
}
}
}
diff --git a/llvm/test/Transforms/InstCombine/fpclass-from-dom-cond.ll b/llvm/test/Transforms/InstCombine/fpclass-from-dom-cond.ll
index e6df7fab356b4a5..934852d1ca8bc42 100644
--- a/llvm/test/Transforms/InstCombine/fpclass-from-dom-cond.ll
+++ b/llvm/test/Transforms/InstCombine/fpclass-from-dom-cond.ll
@@ -528,8 +528,7 @@ define i1 @test_inv_and(float %x, i1 %cond2) {
; CHECK-NEXT: [[AND:%.*]] = and i1 [[COND2]], [[NOT]]
; CHECK-NEXT: br i1 [[AND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then:
-; CHECK-NEXT: [[RET1:%.*]] = fcmp oeq float [[X]], 0x7FF0000000000000
-; CHECK-NEXT: ret i1 [[RET1]]
+; CHECK-NEXT: ret i1 false
; CHECK: if.else:
; CHECK-NEXT: ret i1 false
;
diff --git a/llvm/test/Transforms/InstCombine/known-bits.ll b/llvm/test/Transforms/InstCombine/known-bits.ll
index 7563a63f607f04d..b729cbd971accce 100644
--- a/llvm/test/Transforms/InstCombine/known-bits.ll
+++ b/llvm/test/Transforms/InstCombine/known-bits.ll
@@ -2374,8 +2374,7 @@ define i8 @test_inv_cond_and(i8 %x, i1 %c) {
; CHECK-NEXT: [[COND:%.*]] = and i1 [[C:%.*]], [[NOT]]
; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[EXIT:%.*]]
; CHECK: if:
-; CHECK-NEXT: [[OR1:%.*]] = or i8 [[X]], -4
-; CHECK-NEXT: ret i8 [[OR1]]
+; CHECK-NEXT: ret i8 -4
; CHECK: exit:
; CHECK-NEXT: [[OR2:%.*]] = or i8 [[X]], -4
; CHECK-NEXT: ret i8 [[OR2]]
|
dd461ed
to
ee741c0
Compare
@@ -10272,6 +10280,8 @@ void llvm::findValuesAffectedByCondition( | |||
m_Value()))) { | |||
// Handle patterns that computeKnownFPClass() support. | |||
AddAffected(A); | |||
} else if (!IsAssume && match(V, m_Not(m_Value(X)))) { |
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.
Can we drop the !IsAssume here and instead drop the m_Not special case for assumes above?
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.
to be able to do that isEphemeralValueOf
need to be updated to handle that.
example of test that will fail as the assume is optimized away.
llvm-project/llvm/test/Transforms/GVN/assume.ll
Lines 48 to 61 in 3d14000
define void @pr47496(i8 %x) { | |
; CHECK-LABEL: @pr47496( | |
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 | |
; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[CMP]], true | |
; CHECK-NEXT: call void @llvm.assume(i1 [[XOR]]) | |
; CHECK-NEXT: call void @use(i1 false) | |
; CHECK-NEXT: ret void | |
; | |
%cmp = icmp slt i8 %x, 0 | |
%xor = xor i1 %cmp, true | |
call void @llvm.assume(i1 %xor) | |
call void @use(i1 %cmp) | |
ret void | |
} |
Maybe all instructions with boolean results building up the condition for the assume shall be Ephemeral.
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.
Have some follow up changes that update isEphemeralValueOf
here main...andjo403:llvm-project:assumeNotCond but probably better as multiple PRs if that is something that we want
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
ee741c0
to
394ba6d
Compare
General handling of not in dominating condition. proof: https://alive2.llvm.org/ce/z/FjJN8q
General handling of not in dominating condition. proof: https://alive2.llvm.org/ce/z/FjJN8q
General handling of not in dominating condition.
Split out from #126414
proof: https://alive2.llvm.org/ce/z/FjJN8q