[PATCH] D13733: Perform DIV, REM -> DIVREM combining for all affected nodes at once.
A. Skrobov via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 10:34:46 PDT 2015
tyomitch created this revision.
tyomitch added reviewers: RKSimon, eli.friedman.
tyomitch added a subscriber: llvm-commits.
If the nodes are converted to DIVREM one at a time, then the resulting DIVREM
may get legalized by the backend into something target-specific that we won't
be able to recognize and correlate with the remaining nodes.
This recovers most of the tests broken by the previous patch.
http://reviews.llvm.org/D13733
Files:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2204,20 +2204,37 @@
SDValue Op0 = Node->getOperand(0);
SDValue Op1 = Node->getOperand(1);
+ SDValue combined;
for (SDNode::use_iterator UI = Op0.getNode()->use_begin(),
UE = Op0.getNode()->use_end(); UI != UE; ++UI) {
SDNode *User = *UI;
- if (User == Node)
+ if (User == Node || User->use_empty())
continue;
- // The other use might have been replaced with a divrem already.
- if ((User->getOpcode() == OtherOpcode || User->getOpcode() == DivRemOpc) &&
+ // Convert the other matching node(s), too;
+ // otherwise, the DIVREM may get target-legalized into something
+ // target-specific that we won't be able to recognize.
+ unsigned UserOpc = User->getOpcode();
+ if ((UserOpc == Opcode || UserOpc == OtherOpcode || UserOpc == DivRemOpc) &&
User->getOperand(0) == Op0 &&
User->getOperand(1) == Op1) {
- SDVTList VTs = DAG.getVTList(VT, VT);
- return DAG.getNode(DivRemOpc, SDLoc(Node), VTs, Op0, Op1);
+ if (!combined) {
+ if (UserOpc == OtherOpcode) {
+ SDVTList VTs = DAG.getVTList(VT, VT);
+ combined = DAG.getNode(DivRemOpc, SDLoc(Node), VTs, Op0, Op1);
+ } else if (UserOpc == DivRemOpc) {
+ combined = SDValue(User, 0);
+ } else {
+ assert(UserOpc == Opcode);
+ continue;
+ }
+ }
+ if (UserOpc == ISD::SDIV || UserOpc == ISD::UDIV)
+ CombineTo(User, combined);
+ else if (UserOpc == ISD::SREM || UserOpc == ISD::UREM)
+ CombineTo(User, combined.getValue(1));
}
}
- return SDValue();
+ return combined;
}
SDValue DAGCombiner::visitSDIV(SDNode *N) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13733.37365.patch
Type: text/x-patch
Size: 1876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151014/2323ddb2/attachment.bin>
More information about the llvm-commits
mailing list