This is an archive of the discontinued LLVM Phabricator instance.

Tighten known bits for ctpop based on zero input bits
ClosedPublic

Authored by reames on Sep 29 2015, 10:26 AM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

reames updated this revision to Diff 35996.Sep 29 2015, 10:26 AM
reames retitled this revision from to Tighten known bits for ctpop based on zero input bits.
reames updated this object.
reames added reviewers: majnemer, spatel, hfinkel, regehr.
reames added a subscriber: llvm-commits.
sanjoy added a subscriber: sanjoy.Sep 29 2015, 12:26 PM
sanjoy added inline comments.
lib/Analysis/ValueTracking.cpp
1374 ↗(On Diff #35996)

I think you can also do (with better variable naming :) ):

X = CLZ(BitsPossiblySet);
KnownZero |= APInt::getHighBitsSet(BitWidth, X);
KnownOne &= ~KnownZero;

to avoid the branch, since this would work for BitsPossiblySet == 0 as well.

reames updated this revision to Diff 36654.Oct 6 2015, 1:38 PM

Address Sanjoy's review comments.

ping. Sanjoy?

sanjoy accepted this revision.Oct 14 2015, 3:20 PM
sanjoy added a reviewer: sanjoy.

LGTM.

lib/Analysis/ValueTracking.cpp
1379 ↗(On Diff #36654)

Nit: capitalize We.

Actually, I'd just change this to say // Bits known to be zero ....

This revision is now accepted and ready to land.Oct 14 2015, 3:20 PM
This revision was automatically updated to reflect the committed changes.