[PATCH] D136166: [InstCombine] fmul nnan X, 0.0 --> copysign(0.0, X)
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 18 08:34:12 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG44b7da89d774: [InstCombine] fmul nnan X, 0.0 --> copysign(0.0, X) (authored by spatel).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136166/new/
https://reviews.llvm.org/D136166
Files:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/fmul.ll
Index: llvm/test/Transforms/InstCombine/fmul.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fmul.ll
+++ llvm/test/Transforms/InstCombine/fmul.ll
@@ -1203,22 +1203,26 @@
define half @mul_zero_nnan(half %x) {
; CHECK-LABEL: @mul_zero_nnan(
-; CHECK-NEXT: [[R:%.*]] = fmul nnan half [[X:%.*]], 0xH0000
-; CHECK-NEXT: ret half [[R]]
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan half @llvm.copysign.f16(half 0xH0000, half [[X:%.*]])
+; CHECK-NEXT: ret half [[TMP1]]
;
%r = fmul nnan half %x, 0.0
ret half %r
}
+; poison propagates through vector elements
+
define <2 x float> @mul_zero_nnan_vec_poison(<2 x float> %x) {
; CHECK-LABEL: @mul_zero_nnan_vec_poison(
-; CHECK-NEXT: [[R:%.*]] = fmul nnan <2 x float> [[X:%.*]], <float 0.000000e+00, float poison>
-; CHECK-NEXT: ret <2 x float> [[R]]
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan <2 x float> @llvm.copysign.v2f32(<2 x float> <float 0.000000e+00, float poison>, <2 x float> [[X:%.*]])
+; CHECK-NEXT: ret <2 x float> [[TMP1]]
;
%r = fmul nnan <2 x float> %x, <float 0.0, float poison>
ret <2 x float> %r
}
+; negative test - must have nnan
+
define half @mul_zero(half %x) {
; CHECK-LABEL: @mul_zero(
; CHECK-NEXT: [[R:%.*]] = fmul ninf nsz half [[X:%.*]], 0xH0000
@@ -1228,6 +1232,8 @@
ret half %r
}
+; TODO: This could be fneg+copysign.
+
define half @mul_negzero_nnan(half %x) {
; CHECK-LABEL: @mul_negzero_nnan(
; CHECK-NEXT: [[R:%.*]] = fmul nnan half [[X:%.*]], 0xH8000
Index: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -521,6 +521,13 @@
if (match(Op1, m_SpecificFP(-1.0)))
return UnaryOperator::CreateFNegFMF(Op0, &I);
+ // With no-nans: X * 0.0 --> copysign(0.0, X)
+ if (I.hasNoNaNs() && match(Op1, m_PosZeroFP())) {
+ CallInst *CopySign = Builder.CreateIntrinsic(Intrinsic::copysign,
+ {I.getType()}, {Op1, Op0}, &I);
+ return replaceInstUsesWith(I, CopySign);
+ }
+
// -X * C --> X * -C
Value *X, *Y;
Constant *C;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136166.468565.patch
Type: text/x-patch
Size: 2279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221018/5f1cabff/attachment.bin>
More information about the llvm-commits
mailing list