From: Nikita Popov Date: Tue, 26 Mar 2019 22:37:26 +0000 (+0000) Subject: [ConstantRange] Exclude full set from isSignWrappedSet() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dcc0d9395dae4fa899f5b2fbd560abdf32958ad8;p=llvm [ConstantRange] Exclude full set from isSignWrappedSet() Split off from D59749. This uses a simpler and more efficient implementation of isSignWrappedSet(), and considers full sets as non-wrapped, to be consistent with isWrappedSet(). Otherwise the behavior is unchanged. There are currently only two users of this function and both already check for isFullSet() || isSignWrappedSet(), so this is not going to cause a change in overall behavior. Differential Revision: https://reviews.llvm.org/D59848 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357039 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/ConstantRange.h b/include/llvm/IR/ConstantRange.h index 11481a88fbf..3ac853f3161 100644 --- a/include/llvm/IR/ConstantRange.h +++ b/include/llvm/IR/ConstantRange.h @@ -167,8 +167,10 @@ public: /// For example: [100, 8). bool isWrappedSet() const; - /// Return true if this set wraps around the INT_MIN of - /// its bitwidth. For example: i8 [120, 140). + /// Return true if this set wraps around the signed domain. Special cases: + /// * Empty set: Not wrapped. + /// * Full set: Not wrapped. + /// * [X, SignedMin) == [X, SignedMax]: Not wrapped. bool isSignWrappedSet() const; /// Return true if the specified value is in the set. diff --git a/lib/IR/ConstantRange.cpp b/lib/IR/ConstantRange.cpp index 732f5c03d4e..0c2a3a86597 100644 --- a/lib/IR/ConstantRange.cpp +++ b/lib/IR/ConstantRange.cpp @@ -349,8 +349,7 @@ bool ConstantRange::isWrappedSet() const { } bool ConstantRange::isSignWrappedSet() const { - return contains(APInt::getSignedMaxValue(getBitWidth())) && - contains(APInt::getSignedMinValue(getBitWidth())); + return Lower.sgt(Upper) && !Upper.isMinSignedValue(); } APInt ConstantRange::getSetSize() const { diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp index 058f534249e..c63c6cef7e1 100644 --- a/unittests/IR/ConstantRangeTest.cpp +++ b/unittests/IR/ConstantRangeTest.cpp @@ -161,7 +161,7 @@ TEST_F(ConstantRangeTest, GetMinsAndMaxes) { } TEST_F(ConstantRangeTest, SignWrapped) { - EXPECT_TRUE(Full.isSignWrappedSet()); + EXPECT_FALSE(Full.isSignWrappedSet()); EXPECT_FALSE(Empty.isSignWrappedSet()); EXPECT_FALSE(One.isSignWrappedSet()); EXPECT_FALSE(Some.isSignWrappedSet());