This is an archive of the discontinued LLVM Phabricator instance.

[ConstantRange] Add PreferredResultType support for unionWith()
ClosedPublic

Authored by nikic on Apr 7 2019, 7:41 AM.

Details

Summary

This extends D59959 to unionWith(), allowing to specify that a non-wrapping unsigned/signed range is preferred. This is somewhat less useful than the intersect case, because union operations are rarer. An example use would the the phi union computed in SCEV.

The implementation is mostly a straightforward use of getPreferredRange(), but I also had to adjust some <=/< checks to make sure that no ranges with lower==upper get constructed before they're passed to getPreferredRange(), as these have additional constraints.

Diff Detail

Repository
rL LLVM

Event Timeline

nikic created this revision.Apr 7 2019, 7:41 AM
lebedev.ri added inline comments.Apr 7 2019, 11:27 AM
llvm/lib/IR/ConstantRange.cpp
470 ↗(On Diff #194061)

Please do this as preparatory NFC commit.

609 ↗(On Diff #194061)

And here we have

    //  L---U            : this
    //        L---U      : CR
or
    //        L---U      : this
    //  L---U            : CR

=>

    //  L---------U      : this
or
    //        L--------- : this
    // -----U            : CR

?

635 ↗(On Diff #194061)

So we will produce

    // ----U       L---- : this
    //       L---U       : CR
=>
    // ----------U L----
or
    // ----U L----------

and in either case we bridge either of the gaps?

llvm/unittests/IR/ConstantRangeTest.cpp
367 ↗(On Diff #194061)

Also, could you please do this as NFC commit

nikic updated this revision to Diff 194068.Apr 7 2019, 11:58 AM

Rebase over committed changes.

nikic updated this revision to Diff 194069.Apr 7 2019, 12:18 PM
nikic marked 4 inline comments as done.

Add extra diagrams.

nikic marked 4 inline comments as done.Apr 7 2019, 12:20 PM
nikic added inline comments.
llvm/lib/IR/ConstantRange.cpp
470 ↗(On Diff #194061)

I've included this change while committing D59959.

609 ↗(On Diff #194061)

Right. I've added a comment.

635 ↗(On Diff #194061)

Right. I've added the two possible results to the existing comment.

llvm/unittests/IR/ConstantRangeTest.cpp
367 ↗(On Diff #194061)

Done in rL357874.

lebedev.ri accepted this revision.Apr 7 2019, 12:40 PM

Okay, looks good to me, thank you!

This revision is now accepted and ready to land.Apr 7 2019, 12:40 PM
This revision was automatically updated to reflect the committed changes.
nikic marked 2 inline comments as done.