[llvm-commits] [llvm] r73243 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/fsub-fsub.ll

Dan Gohman gohman at apple.com
Fri Jun 12 12:23:25 PDT 2009


Author: djg
Date: Fri Jun 12 14:23:25 2009
New Revision: 73243

URL: http://llvm.org/viewvc/llvm-project?rev=73243&view=rev
Log:
Don't do (x - (y - z)) --> (x + (z - y)) on floating-point types, because
it may round differently. This fixes PR4374.

Added:
    llvm/trunk/test/Transforms/InstCombine/fsub-fsub.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=73243&r1=73242&r2=73243&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jun 12 14:23:25 2009
@@ -2608,21 +2608,6 @@
       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;

Added: llvm/trunk/test/Transforms/InstCombine/fsub-fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub-fsub.ll?rev=73243&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub-fsub.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/fsub-fsub.ll Fri Jun 12 14:23:25 2009
@@ -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
+}





More information about the llvm-commits mailing list