[PATCH] D139012: InstCombine: Fold out is_fpclass inf checks from test mask for known finite sources

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 10 08:56:28 PST 2022


arsenm updated this revision to Diff 481864.
arsenm added a comment.

Also handle negated case


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

https://reviews.llvm.org/D139012

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/is_fpclass.ll


Index: llvm/test/Transforms/InstCombine/is_fpclass.ll
===================================================================
--- llvm/test/Transforms/InstCombine/is_fpclass.ll
+++ llvm/test/Transforms/InstCombine/is_fpclass.ll
@@ -469,9 +469,7 @@
 
 define i1 @test_class_is_ninf_pinf_ninf_src(float %x) {
 ; CHECK-LABEL: @test_class_is_ninf_pinf_ninf_src(
-; CHECK-NEXT:    [[NINF:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 516)
-; CHECK-NEXT:    ret i1 [[CLASS]]
+; CHECK-NEXT:    ret i1 false
 ;
   %ninf = fadd ninf float %x, 1.0
   %class = call i1 @llvm.is.fpclass.f32(float %ninf, i32 516)
@@ -480,9 +478,7 @@
 
 define i1 @test_class_is_ninf_ninf_src(float %x) {
 ; CHECK-LABEL: @test_class_is_ninf_ninf_src(
-; CHECK-NEXT:    [[NINF:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 4)
-; CHECK-NEXT:    ret i1 [[CLASS]]
+; CHECK-NEXT:    ret i1 false
 ;
   %ninf = fadd ninf float %x, 1.0
   %class = call i1 @llvm.is.fpclass.f32(float %ninf, i32 4)
@@ -491,9 +487,7 @@
 
 define i1 @test_class_is_pinf_ninf_src(float %x) {
 ; CHECK-LABEL: @test_class_is_pinf_ninf_src(
-; CHECK-NEXT:    [[NINF:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 512)
-; CHECK-NEXT:    ret i1 [[CLASS]]
+; CHECK-NEXT:    ret i1 false
 ;
   %ninf = fadd ninf float %x, 1.0
   %class = call i1 @llvm.is.fpclass.f32(float %ninf, i32 512)
@@ -503,7 +497,7 @@
 define i1 @test_class_is_ninf_pinf_pnormal_ninf_src(float %x) {
 ; CHECK-LABEL: @test_class_is_ninf_pinf_pnormal_ninf_src(
 ; CHECK-NEXT:    [[NINF:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 772)
+; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 256)
 ; CHECK-NEXT:    ret i1 [[CLASS]]
 ;
   %ninf = fadd ninf float %x, 1.0
@@ -513,9 +507,7 @@
 
 define i1 @test_class_is_not_inf_ninf_src(float %x) {
 ; CHECK-LABEL: @test_class_is_not_inf_ninf_src(
-; CHECK-NEXT:    [[NINF:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 507)
-; CHECK-NEXT:    ret i1 [[CLASS]]
+; CHECK-NEXT:    ret i1 true
 ;
   %ninf = fadd ninf float %x, 1.0
   %class = call i1 @llvm.is.fpclass.f32(float %ninf, i32 507) ; ~fcInf & fcAllFlags
@@ -524,9 +516,7 @@
 
 define i1 @test_class_is_not_inf_ninf_src_strict(float %x) {
 ; CHECK-LABEL: @test_class_is_not_inf_ninf_src_strict(
-; CHECK-NEXT:    [[NINF:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[NINF]], i32 507) #[[ATTR3]]
-; CHECK-NEXT:    ret i1 [[CLASS]]
+; CHECK-NEXT:    ret i1 true
 ;
   %ninf = fadd ninf float %x, 1.0
   %class = call i1 @llvm.is.fpclass.f32(float %ninf, i32 507) strictfp ; ~fcInf & fcAllFlags
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -856,6 +856,18 @@
     return replaceInstUsesWith(II, ConstantInt::get(II.getType(), true));
   }
 
+  // fp_class (ninf x), ninf|pinf|other -> fp_class (ninf x), other
+  if ((Mask & fcInf) && isKnownNeverInfinity(Src0, &getTargetLibraryInfo())) {
+    return replaceOperand(II, 1,
+                          ConstantInt::get(Src1->getType(), Mask & ~fcInf));
+  }
+
+  // fp_class (ninf x), ~(ninf|pinf) -> true
+  if (Mask == (~fcInf & fcAllFlags) &&
+      isKnownNeverInfinity(Src0, &getTargetLibraryInfo())) {
+    return replaceInstUsesWith(II, ConstantInt::get(II.getType(), true));
+  }
+
   return nullptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139012.481864.patch
Type: text/x-patch
Size: 3891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221210/37013fe2/attachment.bin>


More information about the llvm-commits mailing list