[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Nate Begeman natebegeman at mac.com
Thu Jun 16 00:06:14 PDT 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAG.cpp updated: 1.119 -> 1.120
---
Log message:

Fix bug 537: http://llvm.cs.uiuc.edu/PR537  test 2, which checks to make sure that we fold A+(B-A) -> B for
integer types.  Add a couple checks to not perform these kinds of transform
on floating point values.


---
Diffs of the changes:  (+7 -2)

 SelectionDAG.cpp |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.119 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.120
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.119	Sun May 15 00:39:08 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Thu Jun 16 02:06:03 2005
@@ -1183,12 +1183,17 @@
     if (N2.getOpcode() == ISD::SUB && isa<ConstantSDNode>(N2.getOperand(0)) &&
         cast<ConstantSDNode>(N2.getOperand(0))->getValue() == 0)
       return getNode(ISD::SUB, VT, N1, N2.getOperand(1)); // A+(0-B) -> A-B
+    if (N2.getOpcode() == ISD::SUB && N1 == N2.Val->getOperand(1) &&
+        !MVT::isFloatingPoint(N2.getValueType()))
+      return N2.Val->getOperand(0); // A+(B-A) -> B
     break;
   case ISD::SUB:
     if (N1.getOpcode() == ISD::ADD) {
-      if (N1.Val->getOperand(0) == N2)
+      if (N1.Val->getOperand(0) == N2 && 
+          !MVT::isFloatingPoint(N2.getValueType()))
         return N1.Val->getOperand(1);         // (A+B)-A == B
-      if (N1.Val->getOperand(1) == N2)
+      if (N1.Val->getOperand(1) == N2 &&
+          !MVT::isFloatingPoint(N2.getValueType()))
         return N1.Val->getOperand(0);         // (A+B)-B == A
     }
     if (N2.getOpcode() == ISD::FNEG)          // (A- (-B) -> A+B






More information about the llvm-commits mailing list