From 3190427825181d1663bb49f7c4074901a0a22987 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 28 Feb 2018 22:30:04 +0000 Subject: [PATCH] [InstCombine] simplify code for X * -1.0 --> -X; NFC I've added random FMF to one of the tests to show those are propagated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326377 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 10 +++------- test/Transforms/InstCombine/fmul.ll | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index f79e33fe597..b445c33e88c 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -563,13 +563,9 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) { 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: diff --git a/test/Transforms/InstCombine/fmul.ll b/test/Transforms/InstCombine/fmul.ll index 2eaa7c3e761..34e0047946c 100644 --- a/test/Transforms/InstCombine/fmul.ll +++ b/test/Transforms/InstCombine/fmul.ll @@ -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> , [[X:%.*]] +; CHECK-NEXT: [[MUL:%.*]] = fsub arcp afn <4 x float> , [[X:%.*]] ; CHECK-NEXT: ret <4 x float> [[MUL]] ; - %mul = fmul <4 x float> %x, + %mul = fmul arcp afn <4 x float> %x, ret <4 x float> %mul }