From e54aba5fa959a6196c1d50fe9c229836ec59039e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 12 Jun 2009 19:23:25 +0000 Subject: [PATCH] Don't do (x - (y - z)) --> (x + (z - y)) on floating-point types, because it may round differently. This fixes PR4374. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73243 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 15 --------------- test/Transforms/InstCombine/fsub-fsub.ll | 8 ++++++++ 2 files changed, 8 insertions(+), 15 deletions(-) create mode 100644 test/Transforms/InstCombine/fsub-fsub.ll diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 03a7317138a..5465e4a8846 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2608,21 +2608,6 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y return BinaryOperator::CreateFNeg(Op1I->getOperand(0), I.getName()); } - - if (Op1I->hasOneUse()) { - // Replace (x - (y - z)) with (x + (z - y)) if the (y - z) subexpression - // is not used by anyone else... - // - if (Op1I->getOpcode() == Instruction::FSub) { - // Swap the two operands of the subexpr... - Value *IIOp0 = Op1I->getOperand(0), *IIOp1 = Op1I->getOperand(1); - Op1I->setOperand(0, IIOp1); - Op1I->setOperand(1, IIOp0); - - // Create the new top level fadd instruction... - return BinaryOperator::CreateFAdd(Op0, Op1); - } - } } return 0; diff --git a/test/Transforms/InstCombine/fsub-fsub.ll b/test/Transforms/InstCombine/fsub-fsub.ll new file mode 100644 index 00000000000..ab70479204b --- /dev/null +++ b/test/Transforms/InstCombine/fsub-fsub.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep fsub | count 2 +; PR4374 + +define float @func(float %a, float %b) nounwind { + %tmp3 = fsub float %a, %b + %tmp4 = fsub float -0.000000e+00, %tmp3 + ret float %tmp4 +}