summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-03-09 16:20:52 +0000
committerSanjay Patel <spatel@rotateright.com>2017-03-09 16:20:52 +0000
commit2b1f6f4b92b28278f38812e4497aa115b904b161 (patch)
tree98862032e367f6078260ff41f46422d97d415047 /llvm/lib
parent129edab125931162665df2ceecb87bf917f2425d (diff)
downloadbcm5719-llvm-2b1f6f4b92b28278f38812e4497aa115b904b161.tar.gz
bcm5719-llvm-2b1f6f4b92b28278f38812e4497aa115b904b161.zip
[InstSimplify] vector div/rem with any zero element in divisor is undef
This was suggested as a DAG simplification in the review for rL297026 : http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170306/435253.html ...but let's start with IR since we have actual docs for IR (LangRef). Differential Revision: https://reviews.llvm.org/D30665 llvm-svn: 297390
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 369cf1dd118..f63b1aea795 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1024,6 +1024,17 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv) {
if (match(Op1, m_Zero()))
return UndefValue::get(Ty);
+ // If any element of a constant divisor vector is zero, the whole op is undef.
+ auto *Op1C = dyn_cast<Constant>(Op1);
+ if (Op1C && Ty->isVectorTy()) {
+ unsigned NumElts = Ty->getVectorNumElements();
+ for (unsigned i = 0; i != NumElts; ++i) {
+ Constant *Elt = Op1C->getAggregateElement(i);
+ if (Elt && Elt->isNullValue())
+ return UndefValue::get(Ty);
+ }
+ }
+
// undef / X -> 0
// undef % X -> 0
if (match(Op0, m_Undef()))
OpenPOWER on IntegriCloud