[llvm] r362903 - [InstSimplify] enhance fcmp fold with never-nan operand
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 06:48:59 PDT 2019
Author: spatel
Date: Sun Jun 9 06:48:59 2019
New Revision: 362903
URL: http://llvm.org/viewvc/llvm-project?rev=362903&view=rev
Log:
[InstSimplify] enhance fcmp fold with never-nan operand
This is another step towards correcting our usage of fast-math-flags when applied on an fcmp.
In this case, we are checking for 'nnan' on the fcmp itself rather than the operand of
the fcmp. But I'm leaving that clause in until we're more confident that we can stop
relying on fcmp's FMF.
By using the more general "isKnownNeverNaN()", we gain a simplification shown on the
tests with 'uitofp' regardless of the FMF on the fcmp (uitofp never produces a NaN).
On the tests with 'fabs', we are now relying on the FMF for the call fabs instruction
in addition to the FMF on the fcmp.
This is a continuation of D62979 / rL362879.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=362903&r1=362902&r2=362903&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Jun 9 06:48:59 2019
@@ -3486,8 +3486,8 @@ static Value *SimplifyFCmpInst(unsigned
return getTrue(RetTy);
break;
case FCmpInst::FCMP_ULT:
- // TODO: This should match 'oge'.
- if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ if ((FMF.noNaNs() || isKnownNeverNaN(LHS, Q.TLI)) &&
+ CannotBeOrderedLessThanZero(LHS, Q.TLI))
return getFalse(RetTy);
break;
case FCmpInst::FCMP_OLT:
Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll?rev=362903&r1=362902&r2=362903&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll Sun Jun 9 06:48:59 2019
@@ -313,9 +313,7 @@ define <2 x i1> @UIToFP_is_not_negative_
define i1 @UIToFP_is_not_negative_or_nan(i32 %x) {
; CHECK-LABEL: @UIToFP_is_not_negative_or_nan(
-; CHECK-NEXT: [[A:%.*]] = uitofp i32 [[X:%.*]] to float
-; CHECK-NEXT: [[R:%.*]] = fcmp ult float [[A]], 0.000000e+00
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: ret i1 false
;
%a = uitofp i32 %x to float
%r = fcmp ult float %a, 0.000000e+00
@@ -324,9 +322,7 @@ define i1 @UIToFP_is_not_negative_or_nan
define <2 x i1> @UIToFP_is_not_negative_or_nan_vec(<2 x i32> %x) {
; CHECK-LABEL: @UIToFP_is_not_negative_or_nan_vec(
-; CHECK-NEXT: [[A:%.*]] = uitofp <2 x i32> [[X:%.*]] to <2 x float>
-; CHECK-NEXT: [[R:%.*]] = fcmp ult <2 x float> [[A]], zeroinitializer
-; CHECK-NEXT: ret <2 x i1> [[R]]
+; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%a = uitofp <2 x i32> %x to <2 x float>
%r = fcmp ult <2 x float> %a, zeroinitializer
@@ -425,9 +421,7 @@ define <2 x i1> @fabs_is_not_negative_ve
define i1 @fabs_nnan_is_not_negative(double %x) {
; CHECK-LABEL: @fabs_nnan_is_not_negative(
-; CHECK-NEXT: [[FABS:%.*]] = tail call nnan double @llvm.fabs.f64(double [[X:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ult double [[FABS]], 0.000000e+00
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
%fabs = tail call nnan double @llvm.fabs.f64(double %x)
%cmp = fcmp ult double %fabs, 0.0
@@ -436,9 +430,7 @@ define i1 @fabs_nnan_is_not_negative(dou
define <2 x i1> @fabs_nnan_is_not_negative_vec(<2 x double> %x) {
; CHECK-LABEL: @fabs_nnan_is_not_negative_vec(
-; CHECK-NEXT: [[FABS:%.*]] = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> [[X:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ult <2 x double> [[FABS]], zeroinitializer
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
%cmp = fcmp ult <2 x double> %fabs, zeroinitializer
More information about the llvm-commits
mailing list