This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Understand more select patterns in ComputeKnownBits
ClosedPublic

Authored by jmolloy on Jan 12 2016, 4:31 AM.

Details

Summary

Some patterns of select+compare allow us to know exactly the value of the uppermost bits in the select result. For example:

%b = icmp ugt i32 %a, 5
%c = select i1 %b, i32 2, i32 %a

Here we know that %c is bounded by 5, and therefore KnownZero = ~APInt(5).getActiveBits() = ~7.

There are several such patterns, and this patch attempts to understand a reasonable subset of them - namely when the base values are the same (as above), and when they are related by a simple (add nsw), for example (add nsw %a, 4) and %a.

Diff Detail

Repository
rL LLVM

Event Timeline

jmolloy updated this revision to Diff 44618.Jan 12 2016, 4:31 AM
jmolloy retitled this revision from to [ValueTracking] Understand more select patterns in ComputeKnownBits.
jmolloy updated this object.
jmolloy added reviewers: hfinkel, sanjoy.
jmolloy set the repository for this revision to rL LLVM.
jmolloy added a subscriber: llvm-commits.
mssimpso edited edge metadata.Jan 13 2016, 8:40 AM

James,

Thanks for working on this. I think there's probably a lot of opportunity for this type of work. The patch looks good to me, but feel free to solicit additional feedback if you like.

mcrosier accepted this revision.Jan 13 2016, 9:06 AM
mcrosier edited edge metadata.

LGTM. Looks pretty straight forward and you have test coverage for all the cases.

As Matt pointed out, it seems there's many more opportunities here. I don't know if you plan on implementing additional cases, but if not can you please file a PR with a few comments about follow on work to this patch.

Chad

test/Analysis/ValueTracking/select-maxbits.ll
63

Please add a newline.

This revision is now accepted and ready to land.Jan 13 2016, 9:06 AM
jmolloy closed this revision.Jan 14 2016, 7:27 AM

Thanks! r257769