From 8e937c39bb389e9aeb92467b99e76373bf547bab Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 18 Jan 2014 16:43:14 +0000 Subject: [PATCH] InstCombine: Make the (fmul X, -1.0) -> (fsub -0.0, X) transform handle vectors too. PR18532. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199553 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 10 ++++------ test/Transforms/InstCombine/fmul.ll | 9 +++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index f61d82340b5..2fcd003bcbd 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -425,17 +425,15 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) { if (Instruction *NV = FoldOpIntoPhi(I)) return NV; - ConstantFP *C = dyn_cast(Op1); - // (fmul X, -1.0) --> (fsub -0.0, X) - if (C && C->isExactlyValue(-1.0)) { - Instruction *RI = BinaryOperator::CreateFSub( - ConstantFP::getNegativeZero(C->getType()), - Op0); + if (match(Op1, m_SpecificFP(-1.0))) { + Constant *NegZero = ConstantFP::getNegativeZero(Op1->getType()); + Instruction *RI = BinaryOperator::CreateFSub(NegZero, Op0); RI->copyFastMathFlags(&I); return RI; } + ConstantFP *C = dyn_cast(Op1); if (C && AllowReassociate && C->getValueAPF().isFiniteNonZero()) { // Let MDC denote an expression in one of these forms: // X * C, C/X, X/C, where C is a constant. diff --git a/test/Transforms/InstCombine/fmul.ll b/test/Transforms/InstCombine/fmul.ll index 0b4a90d88fa..fdfc8df0a21 100644 --- a/test/Transforms/InstCombine/fmul.ll +++ b/test/Transforms/InstCombine/fmul.ll @@ -104,3 +104,12 @@ define float @test9(float %x) { ; CHECK: fsub } +; PR18532 +define <4 x float> @test10(<4 x float> %x) { + %mul = fmul <4 x float> %x, + ret <4 x float> %mul + +; CHECK-LABEL: @test10( +; CHECK-NOT: fmul +; CHECK: fsub +}