[llvm] 1a6953a - ValueTracking: Fix bug with fcmp false to nan constant
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 02:22:53 PDT 2024
Author: Matt Arsenault
Date: 2024-03-19T14:52:45+05:30
New Revision: 1a6953a75d3120a4f9196911e6a6b79fcc315553
URL: https://github.com/llvm/llvm-project/commit/1a6953a75d3120a4f9196911e6a6b79fcc315553
DIFF: https://github.com/llvm/llvm-project/commit/1a6953a75d3120a4f9196911e6a6b79fcc315553.diff
LOG: ValueTracking: Fix bug with fcmp false to nan constant
If we had a comparison to a literal nan with a false predicate,
we were incorrectly treating it as an unordered compare. This was
correct for fcmp true, but not fcmp false. I noticed this in the
review for e44d3b3e503fa12fdaead2936b28844aa36237c1 but misdiagnosed
the reason. Also change the test for the fcmp true case to be more
useful, but it wasn't wrong previously.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index fe5d084b55bbe3..2e0a930cf0a32e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3972,10 +3972,16 @@ std::tuple<Value *, FPClassTest, FPClassTest>
llvm::fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
FPClassTest RHSClass, bool LookThroughSrc) {
assert(RHSClass != fcNone);
+ Value *Src = LHS;
+
+ if (Pred == FCmpInst::FCMP_TRUE)
+ return exactClass(Src, fcAllFlags);
+
+ if (Pred == FCmpInst::FCMP_FALSE)
+ return exactClass(Src, fcNone);
const FPClassTest OrigClass = RHSClass;
- Value *Src = LHS;
const bool IsNegativeRHS = (RHSClass & fcNegative) == RHSClass;
const bool IsPositiveRHS = (RHSClass & fcPositive) == RHSClass;
const bool IsNaN = (RHSClass & ~fcNan) == fcNone;
@@ -3994,12 +4000,6 @@ llvm::fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
if (Pred == FCmpInst::FCMP_UNO)
return exactClass(Src, fcNan);
- if (Pred == FCmpInst::FCMP_TRUE)
- return exactClass(Src, fcAllFlags);
-
- if (Pred == FCmpInst::FCMP_FALSE)
- return exactClass(Src, fcNone);
-
const bool IsFabs = LookThroughSrc && match(LHS, m_FAbs(m_Value(Src)));
if (IsFabs)
RHSClass = llvm::inverse_fabs(RHSClass);
diff --git a/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll b/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
index d64f8cf3e56dc1..05c57052e674d7 100644
--- a/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
@@ -2641,8 +2641,8 @@ define float @assume_false_smallest_normal(float %arg) {
}
define float @clamp_false_nan(float %arg) {
-; CHECK-LABEL: define nofpclass(nan inf nzero sub norm) float @clamp_false_nan(
-; CHECK-SAME: float returned nofpclass(nan inf nzero sub norm) [[ARG:%.*]]) #[[ATTR2]] {
+; CHECK-LABEL: define float @clamp_false_nan(
+; CHECK-SAME: float returned [[ARG:%.*]]) #[[ATTR2]] {
; CHECK-NEXT: ret float [[ARG]]
;
%fcmp = fcmp false float %arg, 0x7FF8000000000000
@@ -2784,12 +2784,12 @@ define float @clamp_true_smallest_normal_0.0(float %arg) {
}
define float @clamp_true_nan(float %arg) {
-; CHECK-LABEL: define noundef nofpclass(nan inf nzero sub norm) float @clamp_true_nan(
-; CHECK-SAME: float nofpclass(nan inf nzero sub norm) [[ARG:%.*]]) #[[ATTR2]] {
-; CHECK-NEXT: ret float 0.000000e+00
+; CHECK-LABEL: define float @clamp_true_nan(
+; CHECK-SAME: float returned [[ARG:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT: ret float [[ARG]]
;
%fcmp = fcmp true float %arg, 0x7FF8000000000000
- %select = select i1 %fcmp, float 0.0, float %arg
+ %select = select i1 %fcmp, float %arg, float 0.0
ret float %select
}
More information about the llvm-commits
mailing list