summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-03-09 15:02:25 +0000
committerSanjay Patel <spatel@rotateright.com>2017-03-09 15:02:25 +0000
commitdf21979db7856d80dea6ba4e1a710c6fe3913919 (patch)
tree6a14223a59df64216d649bfc907ccebc1b31dd79 /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parentc206800218c862db45c19b31a11856bb805e7b02 (diff)
downloadbcm5719-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/SelectionDAG.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index d43e7ffab39..d7e97e95e91 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3657,6 +3657,12 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
if (Cst1->isOpaque() || Cst2->isOpaque())
return SDValue();
+ // Division/remainder with a zero divisor is undefined behavior.
+ if ((Opcode == ISD::SDIV || Opcode == ISD::UDIV ||
+ Opcode == ISD::SREM || Opcode == ISD::UREM) &&
+ Cst2->isNullValue())
+ return getUNDEF(VT);
+
std::pair<APInt, bool> Folded = FoldValue(Opcode, Cst1->getAPIntValue(),
Cst2->getAPIntValue());
if (!Folded.second)
OpenPOWER on IntegriCloud