[llvm] 0637b00 - InstSimplify: Use correct interested FP classes when simplifying fcmp
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 31 07:12:04 PDT 2023
Author: Matt Arsenault
Date: 2023-08-31T10:11:52-04:00
New Revision: 0637b00041c7d6a191d51d9966c4f5f41fb97ab5
URL: https://github.com/llvm/llvm-project/commit/0637b00041c7d6a191d51d9966c4f5f41fb97ab5
DIFF: https://github.com/llvm/llvm-project/commit/0637b00041c7d6a191d51d9966c4f5f41fb97ab5.diff
LOG: InstSimplify: Use correct interested FP classes when simplifying fcmp
We are interested in the cases that we don't want, so this was
backwards.
Fixes regression reported after ddb3f12c428bc4bd5a98913d74dfd7f2402bdfd8
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/floating-point-compare.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 130bb2f2ba14ab..040c2e55d87ced 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4129,7 +4129,7 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
// compare isn't a complete class test. e.g. > 1.0 implies fcPositive, but
// isn't implementable as a class call.
if (C->isNegative() && !C->isNegZero()) {
- FPClassTest Interested = fcPositive | fcNan;
+ FPClassTest Interested = KnownFPClass::OrderedLessThanZeroMask;
// FIXME: This assert won't always hold if we depend on the context
// instruction above
@@ -4210,11 +4210,13 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
// TODO: Could fold this with above if there were a matcher which returned all
// classes in a non-splat vector.
if (match(RHS, m_AnyZeroFP())) {
- FPClassTest Interested = FMF.noNaNs() ? fcPositive : fcPositive | fcNan;
-
switch (Pred) {
case FCmpInst::FCMP_OGE:
case FCmpInst::FCMP_ULT: {
+ FPClassTest Interested = KnownFPClass::OrderedLessThanZeroMask;
+ if (!FMF.noNaNs())
+ Interested |= fcNan;
+
KnownFPClass Known = computeLHSClass(Interested);
// Positive or zero X >= 0.0 --> true
@@ -4226,6 +4228,7 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
case FCmpInst::FCMP_UGE:
case FCmpInst::FCMP_OLT: {
+ FPClassTest Interested = KnownFPClass::OrderedLessThanZeroMask;
KnownFPClass Known = computeLHSClass(Interested);
// Positive or zero or nan X >= 0.0 --> true
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
index f6e50940102fa9..62dd37d9b74e62 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -1587,9 +1587,7 @@ define float @fast_square_must_be_positive_daz(float %arg, float %arg1) #0 {
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
-; CHECK-NEXT: [[I4:%.*]] = fcmp olt float [[I3]], 0.000000e+00
-; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
-; CHECK-NEXT: ret float [[I5]]
+; CHECK-NEXT: ret float [[I3]]
;
bb:
%i = fmul float %arg, %arg
@@ -1607,9 +1605,7 @@ define float @fast_square_must_be_positive_daz_nnan(float %arg, float %arg1) #0
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
-; CHECK-NEXT: [[I4:%.*]] = fcmp nnan olt float [[I3]], 0.000000e+00
-; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
-; CHECK-NEXT: ret float [[I5]]
+; CHECK-NEXT: ret float [[I3]]
;
bb:
%i = fmul float %arg, %arg
@@ -1627,9 +1623,7 @@ define float @must_be_olt_negative_constant_daz(float %arg, float %arg1) #0 {
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
-; CHECK-NEXT: [[I4:%.*]] = fcmp olt float [[I3]], -1.000000e+00
-; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
-; CHECK-NEXT: ret float [[I5]]
+; CHECK-NEXT: ret float [[I3]]
;
bb:
%i = fmul float %arg, %arg
@@ -1647,9 +1641,7 @@ define float @must_be_olt_negative_constant_daz_nnan(float %arg, float %arg1) #0
; CHECK-NEXT: [[I:%.*]] = fmul float [[ARG:%.*]], [[ARG]]
; CHECK-NEXT: [[I2:%.*]] = fmul float [[ARG1:%.*]], [[ARG1]]
; CHECK-NEXT: [[I3:%.*]] = fadd float [[I2]], [[I]]
-; CHECK-NEXT: [[I4:%.*]] = fcmp nnan olt float [[I3]], -1.000000e+00
-; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], float 0.000000e+00, float [[I3]]
-; CHECK-NEXT: ret float [[I5]]
+; CHECK-NEXT: ret float [[I3]]
;
bb:
%i = fmul float %arg, %arg
More information about the llvm-commits
mailing list