From a96480ebc187e4e3722b7cdfd582fe3441211b13 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 13 Apr 2019 19:43:45 +0000 Subject: [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 --- llvm/lib/IR/ConstantRange.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'llvm/lib/IR/ConstantRange.cpp') 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, -- cgit v1.2.3