diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-03-09 15:02:25 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-03-09 15:02:25 +0000 |
commit | df21979db7856d80dea6ba4e1a710c6fe3913919 (patch) | |
tree | 6a14223a59df64216d649bfc907ccebc1b31dd79 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | c206800218c862db45c19b31a11856bb805e7b02 (diff) | |
download | bcm5719-llvm-df21979db7856d80dea6ba4e1a710c6fe3913919.tar.gz bcm5719-llvm-df21979db7856d80dea6ba4e1a710c6fe3913919.zip |
[DAG] recognize div/rem by 0 as undef before trying constant folding
As discussed in the review thread for rL297026, this is actually 2 changes that
would independently fix all of the test cases in the patch:
1. Return undef in FoldConstantArithmetic for div/rem by 0.
2. Move basic undef simplifications for div/rem (simplifyDivRem()) before
foldBinopIntoSelect() as a matter of efficiency.
I will handle the case of vectors with any zero element as a follow-up. That change
is the DAG sibling for D30665 + adding a check of vector elements to FoldConstantVectorArithmetic().
I'm deleting the test for PR30693 because it does not test for the actual bug any more
(dangers of using bugpoint).
Differential Revision:
https://reviews.llvm.org/D30741
llvm-svn: 297384
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index ba8f12e8d31..046c9e9520c 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1717,12 +1717,12 @@ SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) { EVT VT = Sel.getValueType(); SDLoc DL(Sel); SDValue NewCT = DAG.getNode(BinOpcode, DL, VT, CT, C1); - assert((isConstantOrConstantVector(NewCT) || + assert((NewCT.isUndef() || isConstantOrConstantVector(NewCT) || isConstantFPBuildVectorOrConstantFP(NewCT)) && "Failed to constant fold a binop with constant operands"); SDValue NewCF = DAG.getNode(BinOpcode, DL, VT, CF, C1); - assert((isConstantOrConstantVector(NewCF) || + assert((NewCF.isUndef() || isConstantOrConstantVector(NewCF) || isConstantFPBuildVectorOrConstantFP(NewCF)) && "Failed to constant fold a binop with constant operands"); @@ -2417,6 +2417,9 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) { if (N1C && N1C->isAllOnesValue()) return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), N0); + if (SDValue V = simplifyDivRem(N, DAG)) + return V; + if (SDValue NewSel = foldBinOpIntoSelect(N)) return NewSel; @@ -2482,9 +2485,6 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) { if (SDValue DivRem = useDivRem(N)) return DivRem; - if (SDValue V = simplifyDivRem(N, DAG)) - return V; - return SDValue(); } @@ -2508,6 +2508,9 @@ SDValue DAGCombiner::visitUDIV(SDNode *N) { N0C, N1C)) return Folded; + if (SDValue V = simplifyDivRem(N, DAG)) + return V; + if (SDValue NewSel = foldBinOpIntoSelect(N)) return NewSel; @@ -2553,9 +2556,6 @@ SDValue DAGCombiner::visitUDIV(SDNode *N) { if (SDValue DivRem = useDivRem(N)) return DivRem; - if (SDValue V = simplifyDivRem(N, DAG)) - return V; - return SDValue(); } @@ -2575,6 +2575,9 @@ SDValue DAGCombiner::visitREM(SDNode *N) { if (SDValue Folded = DAG.FoldConstantArithmetic(Opcode, DL, VT, N0C, N1C)) return Folded; + if (SDValue V = simplifyDivRem(N, DAG)) + return V; + if (SDValue NewSel = foldBinOpIntoSelect(N)) return NewSel; @@ -2629,9 +2632,6 @@ SDValue DAGCombiner::visitREM(SDNode *N) { if (SDValue DivRem = useDivRem(N)) return DivRem.getValue(1); - if (SDValue V = simplifyDivRem(N, DAG)) - return V; - return SDValue(); } |