[ConstantRange] Split makeICmpRegion in two.

Summary:
This change splits `makeICmpRegion` into `makeAllowedICmpRegion` and
`makeSatisfyingICmpRegion` with slightly different contracts.  The first
one is useful for determining what values some expression //may// take,
given that a certain `icmp` evaluates to true.  The second one is useful
for determining what values are guaranteed to //satisfy// a given
`icmp`.

Reviewers: nlewycky

Reviewed By: nlewycky

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D8345

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232575 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjoy Das
2015-03-18 00:41:24 +00:00
parent 8f01b96d93
commit da5f3a3ca5
6 changed files with 96 additions and 20 deletions

View File

@@ -33,6 +33,7 @@
#define LLVM_IR_CONSTANTRANGE_H
#include "llvm/ADT/APInt.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/Support/DataTypes.h"
namespace llvm {
@@ -59,15 +60,27 @@ public:
/// assert out if the two APInt's are not the same bit width.
ConstantRange(APIntMoveTy Lower, APIntMoveTy Upper);
/// Produce the smallest range that contains all values that
/// might satisfy the comparison specified by Pred when compared to any value
/// contained within Other.
/// Produce the smallest range such that all values that may satisfy the given
/// predicate with any value contained within Other is contained in the
/// returned range. Formally, this returns a superset of
/// 'union over all y in Other . { x : icmp op x y is true }'. If the exact
/// answer is not representable as a ConstantRange, the return value will be a
/// proper superset of the above.
///
/// Solves for range X in 'for all x in X, there exists a y in Y such that
/// icmp op x, y is true'. Every value that might make the comparison true
/// is included in the resulting range.
static ConstantRange makeICmpRegion(unsigned Pred,
const ConstantRange &Other);
/// Example: Pred = ult and Other = i8 [2, 5) returns Result = [0, 4)
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred,
const ConstantRange &Other);
/// Produce the largest range such that all values in the returned range
/// satisfy the given predicate with all values contained within Other.
/// Formally, this returns a subset of
/// 'intersection over all y in Other . { x : icmp op x y is true }'. If the
/// exact answer is not representable as a ConstantRange, the return value
/// will be a proper subset of the above.
///
/// Example: Pred = ult and Other = i8 [2, 5) returns [0, 2)
static ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred,
const ConstantRange &Other);
/// Return the lower value for this range.
///