[PATCH] D62979: [InstSimplify] enhance/fix fcmp fold with never-nan operand

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 8 08:12:26 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL362879: [InstSimplify] enhance fcmp fold with never-nan operand (authored by spatel, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62979?vs=203574&id=203694#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62979/new/

https://reviews.llvm.org/D62979

Files:
  llvm/trunk/lib/Analysis/InstructionSimplify.cpp
  llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll


Index: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp
@@ -3477,7 +3477,8 @@
   if (match(RHS, m_AnyZeroFP())) {
     switch (Pred) {
     case FCmpInst::FCMP_OGE:
-      if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
+      if ((FMF.noNaNs() || isKnownNeverNaN(LHS, Q.TLI)) &&
+          CannotBeOrderedLessThanZero(LHS, Q.TLI))
         return getTrue(RetTy);
       break;
     case FCmpInst::FCMP_UGE:
@@ -3485,6 +3486,7 @@
         return getTrue(RetTy);
       break;
     case FCmpInst::FCMP_ULT:
+      // TODO: This should match 'oge'.
       if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
         return getFalse(RetTy);
       break;
Index: llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -257,9 +257,7 @@
 
 define i1 @UIToFP_is_positive_or_zero(i32 %x) {
 ; CHECK-LABEL: @UIToFP_is_positive_or_zero(
-; CHECK-NEXT:    [[A:%.*]] = uitofp i32 [[X:%.*]] to float
-; CHECK-NEXT:    [[R:%.*]] = fcmp oge float [[A]], 0.000000e+00
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 true
 ;
   %a = uitofp i32 %x to float
   %r = fcmp oge float %a, 0.000000e+00
@@ -268,9 +266,7 @@
 
 define <2 x i1> @UIToFP_is_positive_or_zero_vec(<2 x i32> %x) {
 ; CHECK-LABEL: @UIToFP_is_positive_or_zero_vec(
-; CHECK-NEXT:    [[A:%.*]] = uitofp <2 x i32> [[X:%.*]] to <2 x float>
-; CHECK-NEXT:    [[R:%.*]] = fcmp oge <2 x float> [[A]], zeroinitializer
-; CHECK-NEXT:    ret <2 x i1> [[R]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %a = uitofp <2 x i32> %x to <2 x float>
   %r = fcmp oge <2 x float> %a, zeroinitializer
@@ -351,9 +347,7 @@
 
 define i1 @fabs_nnan_is_positive_or_zero(double %x) {
 ; CHECK-LABEL: @fabs_nnan_is_positive_or_zero(
-; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan double @llvm.fabs.f64(double [[X:%.*]])
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp oge double [[FABS]], 0.000000e+00
-; CHECK-NEXT:    ret i1 [[CMP]]
+; CHECK-NEXT:    ret i1 true
 ;
   %fabs = tail call nnan double @llvm.fabs.f64(double %x)
   %cmp = fcmp oge double %fabs, 0.0
@@ -362,9 +356,7 @@
 
 define <2 x i1> @fabs_nnan_is_positive_or_zero_vec(<2 x double> %x) {
 ; CHECK-LABEL: @fabs_nnan_is_positive_or_zero_vec(
-; CHECK-NEXT:    [[FABS:%.*]] = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> [[X:%.*]])
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp oge <2 x double> [[FABS]], zeroinitializer
-; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
   %cmp = fcmp oge <2 x double> %fabs, zeroinitializer


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62979.203694.patch
Type: text/x-patch
Size: 2960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190608/452ee829/attachment.bin>


More information about the llvm-commits mailing list