diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-10-26 21:05:14 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-10-26 21:05:14 +0000 |
commit | cc9e401e3cf11bf353bf7b2734f89fcb74f16d95 (patch) | |
tree | d423c18faa74513d583f237d5493ebc7dc189f92 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 7bf85f5c8dd1a6d49581eaf1fdd489eac79e2115 (diff) | |
download | bcm5719-llvm-cc9e401e3cf11bf353bf7b2734f89fcb74f16d95.tar.gz bcm5719-llvm-cc9e401e3cf11bf353bf7b2734f89fcb74f16d95.zip |
[ValueTracking] peek through shuffles in ComputeNumSignBits (PR37549)
The motivating case is from PR37549:
https://bugs.llvm.org/show_bug.cgi?id=37549
The analysis improvement allows us to form a vector 'select' out of
bitwise logic (the use of ComputeNumSignBits was added at rL345149).
The smaller test shows another InstCombine improvement - we use
ComputeNumSignBits to add 'nsw' to shift-left. But the negative
test shows an example where we must not add 'nsw' - when the shuffle
mask contains undef elements.
Differential Revision: https://reviews.llvm.org/D53659
llvm-svn: 345429
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index b7ff81f9d54..3cef373f324 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2510,6 +2510,27 @@ static unsigned ComputeNumSignBitsImpl(const Value *V, unsigned Depth, // valid for all elements of the vector (for example if vector is sign // extended, shifted, etc). return ComputeNumSignBits(U->getOperand(0), Depth + 1, Q); + + case Instruction::ShuffleVector: + // If the shuffle mask contains any undefined elements, that element of the + // result is undefined. Propagating information from a source operand may + // not be correct in that case, so just bail out. + if (cast<ShuffleVectorInst>(U)->getMask()->containsUndefElement()) + break; + + assert((!isa<UndefValue>(U->getOperand(0)) || + !isa<UndefValue>(U->getOperand(1))) + && "Should have simplified shuffle with 2 undef inputs"); + + // Look through shuffle of 1 source vector. + if (isa<UndefValue>(U->getOperand(0))) + return ComputeNumSignBits(U->getOperand(1), Depth + 1, Q); + if (isa<UndefValue>(U->getOperand(1))) + return ComputeNumSignBits(U->getOperand(0), Depth + 1, Q); + + // TODO: We can look through shuffles of 2 sources by computing the minimum + // sign bits for each operand (similar to what we do for binops). + break; } // Finally, if we can prove that the top bits of the result are 0's or 1's, |