This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Add APInt::isNegatedPowerOf2() helper
ClosedPublic

Authored by RKSimon on Oct 18 2021, 7:52 AM.

Details

Summary

Inspired by D111968, provide a isNegatedPowerOf2() wrapper instead of obfuscating code with (-Value).isPowerOf2() patterns, which I'm sure are likely avenues for typos.....

Diff Detail

Event Timeline

RKSimon created this revision.Oct 18 2021, 7:52 AM
RKSimon requested review of this revision.Oct 18 2021, 7:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2021, 7:52 AM
RKSimon updated this revision to Diff 380444.Oct 18 2021, 9:28 AM

Improved the unit tests

RKSimon updated this revision to Diff 380653.Oct 19 2021, 5:15 AM
RKSimon edited the summary of this revision. (Show Details)
RKSimon added a reviewer: lebedev.ri.

Improved the implementation - we're looking for a shifted mask in the top bits of a non-zero value.

Converted some additional uses of the (-Value).isPowerOf2() pattern

This revision is now accepted and ready to land.Oct 19 2021, 5:19 AM
This revision was automatically updated to reflect the committed changes.