summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-04-13 19:43:45 +0000
committerNikita Popov <nikita.ppv@gmail.com>2019-04-13 19:43:45 +0000
commita96480ebc187e4e3722b7cdfd582fe3441211b13 (patch)
tree46a71de94015672f6a3a7e350b8d69689f412cd6 /llvm/lib/IR/ConstantRange.cpp
parent95e5f28337c9ac5784836d3ecf6ae024ae27b96c (diff)
downloadbcm5719-llvm-a96480ebc187e4e3722b7cdfd582fe3441211b13.tar.gz
bcm5719-llvm-a96480ebc187e4e3722b7cdfd582fe3441211b13.zip
[ConstantRange] Disallow NUW | NSW in makeGuaranteedNoWrapRegion()
As motivated in D60598, this drops support for specifying both NUW and NSW in makeGuaranteedNoWrapRegion(). None of the users of this function currently make use of this. When both NUW and NSW are specified, the exact nowrap region has two disjoint parts and makeGNWR() returns one of them. This result doesn't seem to be useful for anything, but makes the semantics of the function fuzzier. Differential Revision: https://reviews.llvm.org/D60632 llvm-svn: 358340
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index fe67059a892..40934d97286 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -214,8 +214,7 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
assert(Instruction::isBinaryOp(BinOp) && "Binary operators only!");
assert((NoWrapKind == OBO::NoSignedWrap ||
- NoWrapKind == OBO::NoUnsignedWrap ||
- NoWrapKind == (OBO::NoUnsignedWrap | OBO::NoSignedWrap)) &&
+ NoWrapKind == OBO::NoUnsignedWrap) &&
"NoWrapKind invalid!");
unsigned BitWidth = Other.getBitWidth();
@@ -231,11 +230,12 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
if (C->isNullValue())
// Full set: nothing signed / unsigned wraps when added to 0.
return getFull(BitWidth);
- if (NoWrapKind & OBO::NoUnsignedWrap)
- Result =
- SubsetIntersect(Result, ConstantRange(APInt::getNullValue(BitWidth),
- -Other.getUnsignedMax()));
- if (NoWrapKind & OBO::NoSignedWrap) {
+
+ if (NoWrapKind == OBO::NoUnsignedWrap)
+ return ConstantRange(APInt::getNullValue(BitWidth),
+ -Other.getUnsignedMax());
+
+ if (NoWrapKind == OBO::NoSignedWrap) {
const APInt &SignedMin = Other.getSignedMin();
const APInt &SignedMax = Other.getSignedMax();
if (SignedMax.isStrictlyPositive())
@@ -256,11 +256,12 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
if (C->isNullValue())
// Full set: nothing signed / unsigned wraps when subtracting 0.
return getFull(BitWidth);
- if (NoWrapKind & OBO::NoUnsignedWrap)
- Result =
- SubsetIntersect(Result, ConstantRange(Other.getUnsignedMax(),
- APInt::getMinValue(BitWidth)));
- if (NoWrapKind & OBO::NoSignedWrap) {
+
+ if (NoWrapKind == OBO::NoUnsignedWrap)
+ return ConstantRange(Other.getUnsignedMax(),
+ APInt::getMinValue(BitWidth));
+
+ if (NoWrapKind == OBO::NoSignedWrap) {
const APInt &SignedMin = Other.getSignedMin();
const APInt &SignedMax = Other.getSignedMax();
if (SignedMax.isStrictlyPositive())
@@ -275,13 +276,8 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
APInt::getSignedMinValue(BitWidth) + SignedMin));
}
return Result;
- case Instruction::Mul: {
- if (NoWrapKind == (OBO::NoSignedWrap | OBO::NoUnsignedWrap)) {
- return SubsetIntersect(
- makeGuaranteedNoWrapRegion(BinOp, Other, OBO::NoSignedWrap),
- makeGuaranteedNoWrapRegion(BinOp, Other, OBO::NoUnsignedWrap));
- }
+ case Instruction::Mul: {
// Equivalent to calling makeGuaranteedNoWrapRegion() on [V, V+1).
const bool Unsigned = NoWrapKind == OBO::NoUnsignedWrap;
const auto makeSingleValueRegion = [Unsigned,
OpenPOWER on IntegriCloud