From 23019d10067506639ea7221855befbfdd6a25d75 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 24 May 2016 14:18:49 +0000 Subject: [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 --- llvm/lib/Analysis/ValueTracking.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Analysis/ValueTracking.cpp') 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(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(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(Elt) && !isa(Elt)) + return false; + } + return true; + } + return false; } -- cgit v1.2.3