Fix PR2553
authorChris Lattner <sabre@nondot.org>
Thu, 17 Jul 2008 06:07:20 +0000 (06:07 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 17 Jul 2008 06:07:20 +0000 (06:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53715 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/2008-07-16-fsub.ll [new file with mode: 0644]

index 4a45e668cf7ece4fe778f9b5556fc6d2415ee8d6..861badf8f03e5b67e353a4a204331179478ec9ae 100644 (file)
@@ -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/test/Transforms/InstCombine/2008-07-16-fsub.ll b/test/Transforms/InstCombine/2008-07-16-fsub.ll
new file mode 100644 (file)
index 0000000..1d0554d
--- /dev/null
@@ -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
+}