[PATCH] D62661: [DAGCombine] Use FoldConstantArithmetic() to perform ((c1-A)+c2) -> (c1+c2)-A fold

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 12:25:03 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL362130: [DAGCombine] Use FoldConstantArithmetic() to perform ((c1-A)+c2) -> (c1+c2)-A… (authored by lebedevri, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62661?vs=202180&id=202269#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62661/new/

https://reviews.llvm.org/D62661

Files:
  llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2164,10 +2164,10 @@
     // fold ((c1-A)+c2) -> (c1+c2)-A
     if (N0.getOpcode() == ISD::SUB &&
         isConstantOrConstantVector(N0.getOperand(0), /* NoOpaque */ true)) {
-      // FIXME: Adding 2 constants should be handled by FoldConstantArithmetic.
-      return DAG.getNode(ISD::SUB, DL, VT,
-                         DAG.getNode(ISD::ADD, DL, VT, N1, N0.getOperand(0)),
-                         N0.getOperand(1));
+      SDValue Add = DAG.FoldConstantArithmetic(ISD::ADD, DL, VT, N1.getNode(),
+                                               N0.getOperand(0).getNode());
+      assert(Add && "Constant folding failed");
+      return DAG.getNode(ISD::SUB, DL, VT, Add, N0.getOperand(1));
     }
 
     // add (sext i1 X), 1 -> zext (not i1 X)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62661.202269.patch
Type: text/x-patch
Size: 996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190530/20d32338/attachment.bin>


More information about the llvm-commits mailing list