diff options
author | Philip Reames <listmail@philipreames.com> | 2015-10-14 22:42:12 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2015-10-14 22:42:12 +0000 |
commit | ddcf6b35a2dd5d3e00ada5b1a572cb1ff2a5e8fb (patch) | |
tree | 3f300b555b0458246790e5ef572189c90df51ebd /llvm/lib/Analysis | |
parent | 690db6786e6de253b0d3973542484ce528354be9 (diff) | |
download | bcm5719-llvm-ddcf6b35a2dd5d3e00ada5b1a572cb1ff2a5e8fb.tar.gz bcm5719-llvm-ddcf6b35a2dd5d3e00ada5b1a572cb1ff2a5e8fb.zip |
Tighten known bits for ctpop based on zero input bits
This is a cleaned up patch from the one written by John Regehr based on the findings of the Souper superoptimizer.
The basic idea here is that input bits that are known zero reduce the maximum count that the intrinsic could return. We know that the number of bits required to represent a particular count is at most log2(N)+1.
Differential Revision: http://reviews.llvm.org/D13253
llvm-svn: 250338
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 5caffee8fe7..d2a1f8737cd 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1375,8 +1375,18 @@ static void computeKnownBitsFromOperator(Operator *I, APInt &KnownZero, break; } case Intrinsic::ctpop: { - unsigned LowBits = Log2_32(BitWidth)+1; - KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - LowBits); + computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, DL, + Depth + 1, Q); + // We can bound the space the count needs. Also, bits known to be zero + // can't contribute to the population. + unsigned BitsPossiblySet = BitWidth - KnownZero2.countPopulation(); + unsigned LeadingZeros = + APInt(BitWidth, BitsPossiblySet).countLeadingZeros(); + assert(LeadingZeros >= 0 && LeadingZeros <= BitWidth); + KnownZero |= APInt::getHighBitsSet(BitWidth, LeadingZeros); + KnownOne &= ~KnownZero; + // TODO: we could bound KnownOne using the lower bound on the number + // of bits which might be set provided by popcnt KnownOne2. break; } case Intrinsic::fabs: { |