This is an archive of the discontinued LLVM Phabricator instance.

[ConstantRange] Add fromKnownBits() method
ClosedPublic

Authored by nikic on Mar 17 2019, 11:26 AM.

Details

Summary

Following the suggestion in D59450, I'm moving the code for constructing a ConstantRange from KnownBits out of ValueTracking, which also allows us to add a couple of unit tests...

I'm adding this method to ConstantRange rather than KnownBits (which would have been a bit nicer) to avoid creating a dependency from Support to IR, where ConstantRange lives.

PS: C++14 binary literals would be great for these kinds of tests...

Diff Detail

Repository
rL LLVM

Event Timeline

nikic created this revision.Mar 17 2019, 11:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2019, 11:26 AM

Nice!

Would it be possible/reasonable to also add exaustive tests?

nikic updated this revision to Diff 191039.Mar 17 2019, 1:04 PM

Add exhaustive test.

lebedev.ri accepted this revision.Mar 17 2019, 1:12 PM

LGTM, nice, thank you very much!

This revision is now accepted and ready to land.Mar 17 2019, 1:12 PM
This revision was automatically updated to reflect the committed changes.
lebedev.ri added inline comments.Mar 17 2019, 1:26 PM
llvm/lib/IR/ConstantRange.cpp
58–59 ↗(On Diff #191039)

Last-minute thought: should there be a assert(!Known.hasConflict() && "Expected valid KnownBits"); ?
The used methods of KnownBits won't assert that by themselves..

nikic marked 2 inline comments as done.Mar 17 2019, 2:29 PM
nikic added inline comments.
llvm/lib/IR/ConstantRange.cpp
58–59 ↗(On Diff #191039)

I've added this assertion in rL356346.

lebedev.ri added inline comments.Mar 17 2019, 2:39 PM
llvm/lib/IR/ConstantRange.cpp
58–59 ↗(On Diff #191039)

Thanks