This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Correct early out in computeKnownBitsFromOperator to work with non power of 2 bit widths
ClosedPublic

Authored by craig.topper on Jun 13 2017, 1:27 PM.

Details

Summary

There's an early out that's trying to detect when we don't know any bits that make up the legal range of a shift. The code subtracts one from BitWidth which creates a mask in the lower bits for power of 2 bit widths. This is then ANDed with the known bits to see if any of those bits are known. If the bit width isn't a power of 2 this creates a non-sensical mask.

This patch corrects this by rounding up to a power of 2 before doing the subtract and mask.

I found this by inspection. I'll try to put together a test, but wanted to make sure others agreed with my assessment.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Jun 13 2017, 1:27 PM
spatel edited edge metadata.Jun 13 2017, 3:23 PM

The analysis looks right to me - this won't work for non-power-of-2 widths, and there's nothing restricting the possible widths coming into here AFAICT.

Add test case.

Fix formatting

spatel accepted this revision.Jun 14 2017, 9:33 AM

LGTM.

test/Transforms/InstCombine/shift.ll
1309–1317 ↗(On Diff #102490)

A comment or hex values to help explain why this is true would be good.

This revision is now accepted and ready to land.Jun 14 2017, 9:33 AM
This revision was automatically updated to reflect the committed changes.