OSDN Git Service

[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)
commitfbdd8db60192cdeadbcc1ede72a56d240b7b0858
treeff925f840ffb54435c4d8906044e72f7ed82b14b
parentf44199b7bfa7745b7d003bd0c714c53120095845
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357873 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/ConstantRange.h
lib/IR/ConstantRange.cpp
unittests/IR/ConstantRangeTest.cpp