[llvm] r326377 - [InstCombine] simplify code for X * -1.0 --> -X; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 14:30:04 PST 2018
Author: spatel
Date: Wed Feb 28 14:30:04 2018
New Revision: 326377
URL: http://llvm.org/viewvc/llvm-project?rev=326377&view=rev
Log:
[InstCombine] simplify code for X * -1.0 --> -X; NFC
I've added random FMF to one of the tests to show those are propagated.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/fmul.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=326377&r1=326376&r2=326377&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Wed Feb 28 14:30:04 2018
@@ -563,13 +563,9 @@ Instruction *InstCombiner::visitFMul(Bin
if (match(Op0, m_FNeg(m_Value(X))))
return BinaryOperator::CreateFMulFMF(X, ConstantExpr::getFNeg(C), &I);
- // (fmul X, -1.0) --> (fsub -0.0, X)
- if (match(C, m_SpecificFP(-1.0))) {
- Constant *NegZero = ConstantFP::getNegativeZero(Op1->getType());
- Instruction *RI = BinaryOperator::CreateFSub(NegZero, Op0);
- RI->copyFastMathFlags(&I);
- return RI;
- }
+ // X * -1.0 --> -X
+ if (match(C, m_SpecificFP(-1.0)))
+ return BinaryOperator::CreateFNegFMF(Op0, &I);
if (AllowReassociate && C->isFiniteNonZeroFP()) {
// Let MDC denote an expression in one of these forms:
Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul.ll?rev=326377&r1=326376&r2=326377&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Wed Feb 28 14:30:04 2018
@@ -153,10 +153,10 @@ define float @test9(float %x) {
; PR18532
define <4 x float> @test10(<4 x float> %x) {
; CHECK-LABEL: @test10(
-; CHECK-NEXT: [[MUL:%.*]] = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
+; CHECK-NEXT: [[MUL:%.*]] = fsub arcp afn <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
; CHECK-NEXT: ret <4 x float> [[MUL]]
;
- %mul = fmul <4 x float> %x, <float -1.0, float -1.0, float -1.0, float -1.0>
+ %mul = fmul arcp afn <4 x float> %x, <float -1.0, float -1.0, float -1.0, float -1.0>
ret <4 x float> %mul
}
More information about the llvm-commits
mailing list