[ConstantRange] Exclude full set from isSignWrappedSet()
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 26 Mar 2019 22:37:26 +0000 (22:37 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 26 Mar 2019 22:37:26 +0000 (22:37 +0000)
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

llvm-svn: 357039

llvm/include/llvm/IR/ConstantRange.h
llvm/lib/IR/ConstantRange.cpp
llvm/unittests/IR/ConstantRangeTest.cpp

index 11481a88fbfcefbd0840a5af0aee6e0d4934c136..3ac853f3161858832e514fe4535ce68e478cfb1c 100644 (file)
@@ -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.
index 732f5c03d4ed3df0de64cd333d2b2d2dbca1dfec..0c2a3a86597903f14a0e28392b68fa01bafa3b09 100644 (file)
@@ -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 {
index 058f534249e0aef22b6e54d6f8050d1dae9e5e52..c63c6cef7e18873e2ba55d370e50d5a5eefea4b7 100644 (file)
@@ -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());