[llvm] 5ccbd07 - InstCombine: Fold out is_fpclass inf checks from test mask for known finite sources
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 5 05:07:58 PST 2023
Author: Matt Arsenault
Date: 2023-02-05T09:07:53-04:00
New Revision: 5ccbd07dd607bac8a05016d80e3fa34f2d393279
URL: https://github.com/llvm/llvm-project/commit/5ccbd07dd607bac8a05016d80e3fa34f2d393279
DIFF: https://github.com/llvm/llvm-project/commit/5ccbd07dd607bac8a05016d80e3fa34f2d393279.diff
LOG: InstCombine: Fold out is_fpclass inf checks from test mask for known finite sources
Make the partner transform already done for nnan sources.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/is_fpclass.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index bb98693c5e59..2fe8dbeff032 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -866,6 +866,18 @@ Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) {
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())) {
+ II.setArgOperand(1, ConstantInt::get(Src1->getType(), Mask & ~fcInf));
+ return ⅈ
+ }
+
+ // fp_class (ninf x), ~(ninf|pinf) -> true
+ if (Mask == (~fcInf & fcAllFlags) &&
+ isKnownNeverInfinity(Src0, &getTargetLibraryInfo())) {
+ return replaceInstUsesWith(II, ConstantInt::get(II.getType(), true));
+ }
+
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/is_fpclass.ll b/llvm/test/Transforms/InstCombine/is_fpclass.ll
index fae4162f2af3..605f07500950 100644
--- a/llvm/test/Transforms/InstCombine/is_fpclass.ll
+++ b/llvm/test/Transforms/InstCombine/is_fpclass.ll
@@ -469,9 +469,7 @@ define i1 @test_class_is_not_nan_nnan_src_strict(float %x) {
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_pinf_ninf_src(float %x) {
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_ninf_ninf_src(float %x) {
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_pinf_ninf_src(float %x) {
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_ninf_pinf_pnormal_ninf_src(float %x) {
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(float %x) {
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) #[[ATTR2]]
-; 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
More information about the llvm-commits
mailing list