llvm.org GIT mirror llvm / dcc0d93
[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 Nikita Popov 6 months ago
3 changed file(s) with 6 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
166166 /// For example: [100, 8).
167167 bool isWrappedSet() const;
168168
169 /// Return true if this set wraps around the INT_MIN of
170 /// its bitwidth. For example: i8 [120, 140).
169 /// Return true if this set wraps around the signed domain. Special cases:
170 /// * Empty set: Not wrapped.
171 /// * Full set: Not wrapped.
172 /// * [X, SignedMin) == [X, SignedMax]: Not wrapped.
171173 bool isSignWrappedSet() const;
172174
173175 /// Return true if the specified value is in the set.
348348 }
349349
350350 bool ConstantRange::isSignWrappedSet() const {
351 return contains(APInt::getSignedMaxValue(getBitWidth())) &&
352 contains(APInt::getSignedMinValue(getBitWidth()));
351 return Lower.sgt(Upper) && !Upper.isMinSignedValue();
353352 }
354353
355354 APInt ConstantRange::getSetSize() const {
160160 }
161161
162162 TEST_F(ConstantRangeTest, SignWrapped) {
163 EXPECT_TRUE(Full.isSignWrappedSet());
163 EXPECT_FALSE(Full.isSignWrappedSet());
164164 EXPECT_FALSE(Empty.isSignWrappedSet());
165165 EXPECT_FALSE(One.isSignWrappedSet());
166166 EXPECT_FALSE(Some.isSignWrappedSet());