diff options
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/2008-07-16-fsub.ll | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 4a45e668cf7..861badf8f03 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2255,7 +2255,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { Instruction *InstCombiner::visitSub(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - if (Op0 == Op1) // sub X, X -> 0 + if (Op0 == Op1 && // sub X, X -> 0 + !I.getType()->isFPOrFPVector()) return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // If this is a 'B = x-(-A)', change to B = x+A... diff --git a/llvm/test/Transforms/InstCombine/2008-07-16-fsub.ll b/llvm/test/Transforms/InstCombine/2008-07-16-fsub.ll new file mode 100644 index 00000000000..1d0554d1810 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/2008-07-16-fsub.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep sub +; PR2553 + +define double @test(double %X) nounwind { + ; fsub of self can't be optimized away. + %Y = sub double %X, %X + ret double %Y +} |