diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-07-11 09:14:37 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-07-11 09:14:37 +0000 |
commit | 97cf111689572b6c14c04554e1194406e758ca96 (patch) | |
tree | 5b378fd0bec2d65a09465d3dbdf2f622aeef9ef4 /llvm/lib/CodeGen | |
parent | 09f256575b4a21a6e9151d1d0cee0bb435f13e29 (diff) | |
download | bcm5719-llvm-97cf111689572b6c14c04554e1194406e758ca96.tar.gz bcm5719-llvm-97cf111689572b6c14c04554e1194406e758ca96.zip |
[DAGCombiner] Add (urem X, -1) -> select(X == -1, 0, x) fold
llvm-svn: 336773
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 20ea66d8dcc..fa0c4661e14 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3244,6 +3244,8 @@ SDValue DAGCombiner::visitREM(SDNode *N) { SDValue N0 = N->getOperand(0); SDValue N1 = N->getOperand(1); EVT VT = N->getValueType(0); + EVT CCVT = getSetCCResultType(VT); + bool isSigned = (Opcode == ISD::SREM); SDLoc DL(N); @@ -3253,6 +3255,10 @@ SDValue DAGCombiner::visitREM(SDNode *N) { if (N0C && N1C) if (SDValue Folded = DAG.FoldConstantArithmetic(Opcode, DL, VT, N0C, N1C)) return Folded; + // fold (urem X, -1) -> select(X == -1, 0, x) + if (!isSigned && N1C && N1C->getAPIntValue().isAllOnesValue()) + return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ), + DAG.getConstant(0, DL, VT), N0); if (SDValue V = simplifyDivRem(N, DAG)) return V; |