[ConstantRange] Add unsigned and signed intersection types
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 7 Apr 2019 18:44:36 +0000 (18:44 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 7 Apr 2019 18:44:36 +0000 (18:44 +0000)
commit4246106abac4b0803d46936b808f2bb0c7c18887
tree1c3df4daa6cdbf13765c9bf4c039d28ae575eeb0
parenta51883cfab4ea36215549a58f29d65b862ef857c
[ConstantRange] Add unsigned and signed intersection types

The intersection of two ConstantRanges may consist of two disjoint
ranges. As we can only return one range as the result, we need to
return one of the two possible ranges that cover both. Currently the
result is picked based on set size. However, this is not always
optimal: If we're in an unsigned context, we'd prefer to get a large
unsigned range over a small signed range -- the latter effectively
becomes a full set in the unsigned domain.

This revision adds a PreferredRangeType, which can be either Smallest,
Unsigned or Signed. Smallest is the current behavior and Unsigned and
Signed are new variants that prefer not to wrap the unsigned/signed
domain. The new type isn't used anywhere yet (but SCEV will be a good
first user, see D60035).

I've also added some comments to illustrate the various cases in
intersectWith(), which should hopefully make it more obvious what is
going on.

Differential Revision: https://reviews.llvm.org/D59959

llvm-svn: 357873
llvm/include/llvm/IR/ConstantRange.h
llvm/lib/IR/ConstantRange.cpp
llvm/unittests/IR/ConstantRangeTest.cpp