[PATCH] D62661: [DAGCombine] Use FoldConstantArithmetic() to perform ((c1-A)+c2) -> (c1+c2)-A fold
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 30 07:14:15 PDT 2019
lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, RKSimon, craig.topper.
lebedev.ri added a project: LLVM.
lebedev.ri added a child revision: D62662: [DAGCombine] ((A-c1)+c2) -> (A+(c2-c1)) constant-fold.
No tests change, and i'm not sure how to test this, but it's better safe than sorry.
Repository:
rL LLVM
https://reviews.llvm.org/D62661
Files:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ 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.202180.patch
Type: text/x-patch
Size: 963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190530/de155b67/attachment.bin>
More information about the llvm-commits
mailing list