[llvm] 19d428f - InstCombine: Fold negations of is_fpclass intrinsics
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 05:06:25 PST 2022
Author: Matt Arsenault
Date: 2022-12-13T08:06:19-05:00
New Revision: 19d428f717e773d9c74f5a8452c68c1bb56fc6f0
URL: https://github.com/llvm/llvm-project/commit/19d428f717e773d9c74f5a8452c68c1bb56fc6f0
DIFF: https://github.com/llvm/llvm-project/commit/19d428f717e773d9c74f5a8452c68c1bb56fc6f0.diff
LOG: InstCombine: Fold negations of is_fpclass intrinsics
Can invert the result by inverting the test mask.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/is_fpclass.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 7218e896c37f..3d21f253e365 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3743,6 +3743,14 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) {
Value *InvMaxMin = Builder.CreateBinaryIntrinsic(InvID, X, NotY);
return replaceInstUsesWith(I, InvMaxMin);
}
+
+ if (II->getIntrinsicID() == Intrinsic::is_fpclass) {
+ ConstantInt *ClassMask = cast<ConstantInt>(II->getArgOperand(1));
+ II->setArgOperand(
+ 1, ConstantInt::get(ClassMask->getType(),
+ ~ClassMask->getZExtValue() & fcAllFlags));
+ return replaceInstUsesWith(I, II);
+ }
}
if (NotOp->hasOneUse()) {
diff --git a/llvm/test/Transforms/InstCombine/is_fpclass.ll b/llvm/test/Transforms/InstCombine/is_fpclass.ll
index a5480560152d..68b65a9b94a6 100644
--- a/llvm/test/Transforms/InstCombine/is_fpclass.ll
+++ b/llvm/test/Transforms/InstCombine/is_fpclass.ll
@@ -357,9 +357,8 @@ define i1 @test_class_is_nan_other_nnan_src(float %x) {
define i1 @test_class_not_is_nan(float %x) {
; CHECK-LABEL: define {{[^@]+}}@test_class_not_is_nan(
-; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 3)
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CLASS]], true
-; CHECK-NEXT: ret i1 [[NOT]]
+; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 1020)
+; CHECK-NEXT: ret i1 [[CLASS]]
;
%class = call i1 @llvm.is.fpclass.f32(float %x, i32 3)
%not = xor i1 %class, true
@@ -381,9 +380,8 @@ define i1 @test_class_not_is_nan_multi_use(float %x, ptr %ptr) {
define i1 @test_class_not_is_inf_nan(float %x) {
; CHECK-LABEL: define {{[^@]+}}@test_class_not_is_inf_nan(
-; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 519)
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CLASS]], true
-; CHECK-NEXT: ret i1 [[NOT]]
+; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 504)
+; CHECK-NEXT: ret i1 [[CLASS]]
;
%class = call i1 @llvm.is.fpclass.f32(float %x, i32 519)
%not = xor i1 %class, true
@@ -392,9 +390,8 @@ define i1 @test_class_not_is_inf_nan(float %x) {
define i1 @test_class_not_is_normal(float %x) {
; CHECK-LABEL: define {{[^@]+}}@test_class_not_is_normal(
-; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 264)
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[CLASS]], true
-; CHECK-NEXT: ret i1 [[NOT]]
+; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 759)
+; CHECK-NEXT: ret i1 [[CLASS]]
;
%class = call i1 @llvm.is.fpclass.f32(float %x, i32 264)
%not = xor i1 %class, true
@@ -413,9 +410,8 @@ define i1 @test_class_xor_false(float %x) {
define <2 x i1> @test_class_not_vector(<2 x float> %x) {
; CHECK-LABEL: define {{[^@]+}}@test_class_not_vector(
-; CHECK-NEXT: [[CLASS:%.*]] = call <2 x i1> @llvm.is.fpclass.v2f32(<2 x float> [[X:%.*]], i32 33)
-; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i1> [[CLASS]], <i1 true, i1 true>
-; CHECK-NEXT: ret <2 x i1> [[NOT]]
+; CHECK-NEXT: [[CLASS:%.*]] = call <2 x i1> @llvm.is.fpclass.v2f32(<2 x float> [[X:%.*]], i32 990)
+; CHECK-NEXT: ret <2 x i1> [[CLASS]]
;
%class = call <2 x i1> @llvm.is.fpclass.v2f32(<2 x float> %x, i32 33)
%not = xor <2 x i1> %class, <i1 true, i1 true>
More information about the llvm-commits
mailing list