[PATCH] D138180: InstCombine: Fold negations of is_fpclass intrinsics
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 16 21:36:44 PST 2022
arsenm created this revision.
arsenm added reviewers: sepavloff, spatel, kpn, andrew.w.kaylor, jcranmer-intel, foad.
Herald added a subscriber: hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
Can invert the result by inverting the test mask.
https://reviews.llvm.org/D138180
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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
@@ -417,9 +417,8 @@
define i1 @test_class_not_is_inf_nan(float %x) {
; CHECK-LABEL: @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
@@ -428,9 +427,8 @@
define i1 @test_class_not_is_normal(float %x) {
; CHECK-LABEL: @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
@@ -449,9 +447,8 @@
define <2 x i1> @test_class_not_vector(<2 x float> %x) {
; CHECK-LABEL: @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>
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3709,6 +3709,14 @@
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()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138180.476005.patch
Type: text/x-patch
Size: 2622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221117/df8c54ec/attachment.bin>
More information about the llvm-commits
mailing list