add a simple xform
authorChris Lattner <sabre@nondot.org>
Sun, 10 Apr 2005 04:04:49 +0000 (04:04 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 10 Apr 2005 04:04:49 +0000 (04:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21203 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index f33ecd72239337ab05bfeaa140ac2b4b0edd1a6a..7cf89144c3b51bdb166a3dd8072bb12c731b06cb 100644 (file)
@@ -892,6 +892,12 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
       return getNode(ISD::SUB, VT, N1, N2.getOperand(0));
     if (N1.getOpcode() == ISD::FNEG)          // ((-A)+B) -> B-A
       return getNode(ISD::SUB, VT, N2, N1.getOperand(0));
+    if (N1.getOpcode() == ISD::SUB && isa<ConstantSDNode>(N1.getOperand(0)) &&
+        cast<ConstantSDNode>(N1.getOperand(0))->getValue() == 0)
+      return getNode(ISD::SUB, VT, N2, N1.getOperand(1)); // (0-A)+B -> B-A
+    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
     break;
   case ISD::SUB:
     if (N1.getOpcode() == ISD::ADD) {