diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-05-24 14:18:49 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-05-24 14:18:49 +0000 |
commit | 23019d10067506639ea7221855befbfdd6a25d75 (patch) | |
tree | e04095c4e84b8e6321ee0c82128cf6b9ef8d38aa /llvm/lib | |
parent | 0295fbe1bba602566d7ebc605feda2edde812840 (diff) | |
download | bcm5719-llvm-23019d10067506639ea7221855befbfdd6a25d75.tar.gz bcm5719-llvm-23019d10067506639ea7221855befbfdd6a25d75.zip |
[ValueTracking, InstSimplify] extend isKnownNonZero() to handle vector constants
Similar in spirit to D20497 :
If all elements of a constant vector are known non-zero, then we can say that the
whole vector is known non-zero.
It seems like we could extend this to FP scalar/vector too, but isKnownNonZero()
says it only works for integers and pointers for now.
Differential Revision: http://reviews.llvm.org/D20544
llvm-svn: 270562
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index d4602dd5053..8a0695c325d 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1678,7 +1678,20 @@ bool isKnownNonZero(Value *V, unsigned Depth, const Query &Q) { if (isa<ConstantInt>(C)) // Must be non-zero due to null test above. return true; - // TODO: Handle vectors + + // For constant vectors, check that all elements are undefined or known + // non-zero to determine that the whole vector is known non-zero. + if (auto *VecTy = dyn_cast<VectorType>(C->getType())) { + for (unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) { + Constant *Elt = C->getAggregateElement(i); + if (!Elt || Elt->isNullValue()) + return false; + if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt)) + return false; + } + return true; + } + return false; } |