diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-07-10 13:18:16 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-07-10 13:18:16 +0000 |
commit | 641097d561b28d55942b0ed6891e7d9ee92809c2 (patch) | |
tree | 70fa79851db9744c907324d424ec2479f039ac2b /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | b1f95697c10e84da63b952baf3020d2e149e6d6a (diff) | |
download | bcm5719-llvm-641097d561b28d55942b0ed6891e7d9ee92809c2.tar.gz bcm5719-llvm-641097d561b28d55942b0ed6891e7d9ee92809c2.zip |
[DAGCombiner] visitREM - call visitSDIVLike/visitUDIVLike directly to avoid recursive combining.
As suggested by @efriedma on D48975 use the visitSDIVLike/visitUDIVLike functions introduced at rL336656.
llvm-svn: 336664
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 3d51a43a8c9..7c668a1f931 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3277,22 +3277,19 @@ SDValue DAGCombiner::visitREM(SDNode *N) { // If X/C can be simplified by the division-by-constant logic, lower // X%C to the equivalent of X-X/C*C. - // To avoid mangling nodes, this simplification requires that the combine() - // call for the speculative DIV must not cause a DIVREM conversion. We guard - // against this by skipping the simplification if isIntDivCheap(). When - // div is not cheap, combine will not return a DIVREM. Regardless, - // checking cheapness here makes sense since the simplification results in - // fatter code. + // Reuse the SDIVLike/UDIVLike combines - to avoid mangling nodes, the + // speculative DIV must not cause a DIVREM conversion. We guard against this + // by skipping the simplification if isIntDivCheap(). When div is not cheap, + // combine will not return a DIVREM. Regardless, checking cheapness here + // makes sense since the simplification results in fatter code. if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap(VT, Attr)) { - unsigned DivOpcode = isSigned ? ISD::SDIV : ISD::UDIV; - SDValue Div = DAG.getNode(DivOpcode, DL, VT, N0, N1); - AddToWorklist(Div.getNode()); - SDValue OptimizedDiv = combine(Div.getNode()); - if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != Div.getNode() && - OptimizedDiv.getOpcode() != ISD::UDIVREM && + SDValue OptimizedDiv = + isSigned ? visitSDIVLike(N0, N1, N) : visitUDIVLike(N0, N1, N); + if (OptimizedDiv.getNode() && OptimizedDiv.getOpcode() != ISD::UDIVREM && OptimizedDiv.getOpcode() != ISD::SDIVREM) { SDValue Mul = DAG.getNode(ISD::MUL, DL, VT, OptimizedDiv, N1); SDValue Sub = DAG.getNode(ISD::SUB, DL, VT, N0, Mul); + AddToWorklist(OptimizedDiv.getNode()); AddToWorklist(Mul.getNode()); return Sub; } |