[llvm] 9e85efb - [ConstantRangeTest] Set APInt signed flags where needed (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 07:11:14 PDT 2024
Author: Nikita Popov
Date: 2024-09-05T16:11:00+02:00
New Revision: 9e85efb0dec8e78ca69925a05c0bbba211dee507
URL: https://github.com/llvm/llvm-project/commit/9e85efb0dec8e78ca69925a05c0bbba211dee507
DIFF: https://github.com/llvm/llvm-project/commit/9e85efb0dec8e78ca69925a05c0bbba211dee507.diff
LOG: [ConstantRangeTest] Set APInt signed flags where needed (NFC)
Split out from https://github.com/llvm/llvm-project/pull/80309 to
avoid assertion failures in the future.
Added:
Modified:
llvm/unittests/IR/ConstantRangeTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 4815117458b9af..e1d9b3e387b200 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -372,10 +372,10 @@ TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
EXPECT_EQ(Some.getSignedMax(), APInt(16, 0xaa9));
EXPECT_EQ(Wrap.getSignedMax(), APInt(16, INT16_MAX));
- EXPECT_EQ(Full.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
+ EXPECT_EQ(Full.getSignedMin(), APInt(16, (uint16_t)INT16_MIN));
EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa));
EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa));
- EXPECT_EQ(Wrap.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
+ EXPECT_EQ(Wrap.getSignedMin(), APInt(16, (uint16_t)INT16_MIN));
// Found by Klee
EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(),
@@ -487,7 +487,7 @@ TEST_F(ConstantRangeTest, SExt) {
APInt(20, INT16_MAX + 1, true)));
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16),
- ConstantRange(APInt(16, -128), APInt(16, 128)));
+ ConstantRange(APInt(16, -128, true), APInt(16, 128)));
EXPECT_EQ(ConstantRange(APInt(16, 0x0200), APInt(16, 0x8000)).signExtend(19),
ConstantRange(APInt(19, 0x0200), APInt(19, 0x8000)));
@@ -516,7 +516,7 @@ TEST_F(ConstantRangeTest, IntersectWith) {
EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
// previous bug: intersection of [min, 3) and [2, max) should be 2
- LHS = ConstantRange(APInt(32, -2147483646), APInt(32, 3));
+ LHS = ConstantRange(APInt(32, (uint32_t)-2147483646), APInt(32, 3));
RHS = ConstantRange(APInt(32, 2), APInt(32, 2147483646));
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2)));
@@ -744,45 +744,51 @@ TEST_F(ConstantRangeTest, AddWithNoWrap) {
EXPECT_NE(Some.addWithNoWrap(Full, OBO::NoSignedWrap), Full);
EXPECT_EQ(Full.addWithNoWrap(ConstantRange(APInt(16, 1), APInt(16, 2)),
OBO::NoSignedWrap),
- ConstantRange(APInt(16, INT16_MIN + 1), APInt(16, INT16_MIN)));
+ ConstantRange(APInt(16, INT16_MIN + 1, true),
+ APInt(16, INT16_MIN, true)));
EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 2))
.addWithNoWrap(Full, OBO::NoSignedWrap),
- ConstantRange(APInt(16, INT16_MIN + 1), APInt(16, INT16_MIN)));
- EXPECT_EQ(Full.addWithNoWrap(ConstantRange(APInt(16, -1), APInt(16, 0)),
+ ConstantRange(APInt(16, INT16_MIN + 1, true),
+ APInt(16, INT16_MIN, true)));
+ EXPECT_EQ(Full.addWithNoWrap(ConstantRange(APInt(16, -1, true), APInt(16, 0)),
OBO::NoSignedWrap),
- ConstantRange(APInt(16, INT16_MIN), APInt(16, INT16_MAX)));
+ ConstantRange(APInt(16, INT16_MIN, true), APInt(16, INT16_MAX)));
EXPECT_EQ(ConstantRange(APInt(8, 100), APInt(8, 120))
.addWithNoWrap(ConstantRange(APInt(8, 120), APInt(8, 123)),
OBO::NoSignedWrap),
ConstantRange(8, false));
- EXPECT_EQ(ConstantRange(APInt(8, -120), APInt(8, -100))
- .addWithNoWrap(ConstantRange(APInt(8, -110), APInt(8, -100)),
- OBO::NoSignedWrap),
+ EXPECT_EQ(ConstantRange(APInt(8, -120, true), APInt(8, -100, true))
+ .addWithNoWrap(
+ ConstantRange(APInt(8, -110, true), APInt(8, -100, true)),
+ OBO::NoSignedWrap),
ConstantRange(8, false));
- EXPECT_EQ(ConstantRange(APInt(8, 0), APInt(8, 101))
- .addWithNoWrap(ConstantRange(APInt(8, -128), APInt(8, 28)),
- OBO::NoSignedWrap),
- ConstantRange(8, true));
- EXPECT_EQ(ConstantRange(APInt(8, 0), APInt(8, 101))
- .addWithNoWrap(ConstantRange(APInt(8, -120), APInt(8, 29)),
- OBO::NoSignedWrap),
- ConstantRange(APInt(8, -120), APInt(8, -128)));
- EXPECT_EQ(ConstantRange(APInt(8, -50), APInt(8, 50))
+ EXPECT_EQ(
+ ConstantRange(APInt(8, 0), APInt(8, 101))
+ .addWithNoWrap(ConstantRange(APInt(8, -128, true), APInt(8, 28)),
+ OBO::NoSignedWrap),
+ ConstantRange(8, true));
+ EXPECT_EQ(
+ ConstantRange(APInt(8, 0), APInt(8, 101))
+ .addWithNoWrap(ConstantRange(APInt(8, -120, true), APInt(8, 29)),
+ OBO::NoSignedWrap),
+ ConstantRange(APInt(8, -120, true), APInt(8, -128, true)));
+ EXPECT_EQ(ConstantRange(APInt(8, -50, true), APInt(8, 50))
.addWithNoWrap(ConstantRange(APInt(8, 10), APInt(8, 20)),
OBO::NoSignedWrap),
- ConstantRange(APInt(8, -40), APInt(8, 69)));
+ ConstantRange(APInt(8, -40, true), APInt(8, 69)));
EXPECT_EQ(ConstantRange(APInt(8, 10), APInt(8, 20))
- .addWithNoWrap(ConstantRange(APInt(8, -50), APInt(8, 50)),
+ .addWithNoWrap(ConstantRange(APInt(8, -50, true), APInt(8, 50)),
OBO::NoSignedWrap),
- ConstantRange(APInt(8, -40), APInt(8, 69)));
- EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, -10))
+ ConstantRange(APInt(8, -40, true), APInt(8, 69)));
+ EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, -10, true))
.addWithNoWrap(ConstantRange(APInt(8, 5), APInt(8, 20)),
OBO::NoSignedWrap),
ConstantRange(APInt(8, 125), APInt(8, 9)));
- EXPECT_EQ(ConstantRange(APInt(8, 5), APInt(8, 20))
- .addWithNoWrap(ConstantRange(APInt(8, 120), APInt(8, -10)),
- OBO::NoSignedWrap),
- ConstantRange(APInt(8, 125), APInt(8, 9)));
+ EXPECT_EQ(
+ ConstantRange(APInt(8, 5), APInt(8, 20))
+ .addWithNoWrap(ConstantRange(APInt(8, 120), APInt(8, -10, true)),
+ OBO::NoSignedWrap),
+ ConstantRange(APInt(8, 125), APInt(8, 9)));
TestBinaryOpExhaustive(
[](const ConstantRange &CR1, const ConstantRange &CR2) {
@@ -827,15 +833,15 @@ TEST_F(ConstantRangeTest, AddWithNoWrap) {
EXPECT_EQ(ConstantRange(APInt(8, 10), APInt(8, 20))
.addWithNoWrap(ConstantRange(APInt(8, 50), APInt(8, 200)),
OBO::NoUnsignedWrap),
- ConstantRange(APInt(8, 60), APInt(8, -37)));
- EXPECT_EQ(ConstantRange(APInt(8, 20), APInt(8, -30))
+ ConstantRange(APInt(8, 60), APInt(8, -37, true)));
+ EXPECT_EQ(ConstantRange(APInt(8, 20), APInt(8, -30, true))
.addWithNoWrap(ConstantRange(APInt(8, 5), APInt(8, 20)),
OBO::NoUnsignedWrap),
- ConstantRange(APInt(8, 25), APInt(8, -11)));
+ ConstantRange(APInt(8, 25), APInt(8, -11, true)));
EXPECT_EQ(ConstantRange(APInt(8, 5), APInt(8, 20))
- .addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, -30)),
+ .addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, -30, true)),
OBO::NoUnsignedWrap),
- ConstantRange(APInt(8, 25), APInt(8, -11)));
+ ConstantRange(APInt(8, 25), APInt(8, -11, true)));
TestBinaryOpExhaustive(
[](const ConstantRange &CR1, const ConstantRange &CR2) {
@@ -853,7 +859,7 @@ TEST_F(ConstantRangeTest, AddWithNoWrap) {
EXPECT_EQ(ConstantRange(APInt(8, 50), APInt(8, 100))
.addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, 70)),
OBO::NoSignedWrap),
- ConstantRange(APInt(8, 70), APInt(8, -128)));
+ ConstantRange(APInt(8, 70), APInt(8, -128, true)));
EXPECT_EQ(ConstantRange(APInt(8, 50), APInt(8, 100))
.addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, 70)),
OBO::NoUnsignedWrap),
@@ -861,17 +867,17 @@ TEST_F(ConstantRangeTest, AddWithNoWrap) {
EXPECT_EQ(ConstantRange(APInt(8, 50), APInt(8, 100))
.addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, 70)),
OBO::NoUnsignedWrap | OBO::NoSignedWrap),
- ConstantRange(APInt(8, 70), APInt(8, -128)));
+ ConstantRange(APInt(8, 70), APInt(8, -128, true)));
- EXPECT_EQ(ConstantRange(APInt(8, -100), APInt(8, -50))
+ EXPECT_EQ(ConstantRange(APInt(8, -100, true), APInt(8, -50, true))
.addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, 30)),
OBO::NoSignedWrap),
- ConstantRange(APInt(8, -80), APInt(8, -21)));
- EXPECT_EQ(ConstantRange(APInt(8, -100), APInt(8, -50))
+ ConstantRange(APInt(8, -80, true), APInt(8, -21, true)));
+ EXPECT_EQ(ConstantRange(APInt(8, -100, true), APInt(8, -50, true))
.addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, 30)),
OBO::NoUnsignedWrap),
ConstantRange(APInt(8, 176), APInt(8, 235)));
- EXPECT_EQ(ConstantRange(APInt(8, -100), APInt(8, -50))
+ EXPECT_EQ(ConstantRange(APInt(8, -100, true), APInt(8, -50, true))
.addWithNoWrap(ConstantRange(APInt(8, 20), APInt(8, 30)),
OBO::NoUnsignedWrap | OBO::NoSignedWrap),
ConstantRange(APInt(8, 176), APInt(8, 235)));
@@ -1004,17 +1010,17 @@ TEST_F(ConstantRangeTest, Multiply) {
ConstantRange(APInt(8, 250), APInt(8, 253)));
// TODO: This should be return [-2, 0]
- EXPECT_EQ(ConstantRange(APInt(8, -2)).multiply(
- ConstantRange(APInt(8, 0), APInt(8, 2))),
- ConstantRange(APInt(8, -2), APInt(8, 1)));
+ EXPECT_EQ(ConstantRange(APInt(8, -2, true))
+ .multiply(ConstantRange(APInt(8, 0), APInt(8, 2))),
+ ConstantRange(APInt(8, -2, true), APInt(8, 1)));
// Multiplication by -1 should give precise results.
- EXPECT_EQ(ConstantRange(APInt(8, 3), APInt(8, -11))
- .multiply(ConstantRange(APInt(8, -1))),
- ConstantRange(APInt(8, 12), APInt(8, -2)));
- EXPECT_EQ(ConstantRange(APInt(8, -1))
- .multiply(ConstantRange(APInt(8, 3), APInt(8, -11))),
- ConstantRange(APInt(8, 12), APInt(8, -2)));
+ EXPECT_EQ(ConstantRange(APInt(8, 3), APInt(8, -11, true))
+ .multiply(ConstantRange(APInt(8, -1, true))),
+ ConstantRange(APInt(8, 12), APInt(8, -2, true)));
+ EXPECT_EQ(ConstantRange(APInt(8, -1, true))
+ .multiply(ConstantRange(APInt(8, 3), APInt(8, -11, true))),
+ ConstantRange(APInt(8, 12), APInt(8, -2, true)));
TestBinaryOpExhaustive(
[](const ConstantRange &CR1, const ConstantRange &CR2) {
@@ -1185,11 +1191,11 @@ TEST_F(ConstantRangeTest, SMax) {
EXPECT_EQ(Empty.smax(Wrap), Empty);
EXPECT_EQ(Empty.smax(One), Empty);
EXPECT_EQ(Some.smax(Some), Some);
- EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
- APInt(16, (uint64_t)INT16_MIN)));
+ EXPECT_EQ(Some.smax(Wrap),
+ ConstantRange(APInt(16, 0xa), APInt(16, (uint16_t)INT16_MIN)));
EXPECT_EQ(Some.smax(One), Some);
- EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
- APInt(16, (uint64_t)INT16_MIN)));
+ EXPECT_EQ(Wrap.smax(One),
+ ConstantRange(APInt(16, 0xa), APInt(16, (uint16_t)INT16_MIN)));
EXPECT_EQ(One.smax(One), One);
TestBinaryOpExhaustive(
@@ -1231,20 +1237,20 @@ TEST_F(ConstantRangeTest, UMin) {
TEST_F(ConstantRangeTest, SMin) {
EXPECT_EQ(Full.smin(Full), Full);
EXPECT_EQ(Full.smin(Empty), Empty);
- EXPECT_EQ(Full.smin(Some), ConstantRange(APInt(16, (uint64_t)INT16_MIN),
- APInt(16, 0xaaa)));
+ EXPECT_EQ(Full.smin(Some),
+ ConstantRange(APInt(16, (uint16_t)INT16_MIN), APInt(16, 0xaaa)));
EXPECT_EQ(Full.smin(Wrap), Full);
EXPECT_EQ(Empty.smin(Empty), Empty);
EXPECT_EQ(Empty.smin(Some), Empty);
EXPECT_EQ(Empty.smin(Wrap), Empty);
EXPECT_EQ(Empty.smin(One), Empty);
EXPECT_EQ(Some.smin(Some), Some);
- EXPECT_EQ(Some.smin(Wrap), ConstantRange(APInt(16, (uint64_t)INT16_MIN),
- APInt(16, 0xaaa)));
+ EXPECT_EQ(Some.smin(Wrap),
+ ConstantRange(APInt(16, (uint16_t)INT16_MIN), APInt(16, 0xaaa)));
EXPECT_EQ(Some.smin(One), One);
EXPECT_EQ(Wrap.smin(Wrap), Wrap);
- EXPECT_EQ(Wrap.smin(One), ConstantRange(APInt(16, (uint64_t)INT16_MIN),
- APInt(16, 0xb)));
+ EXPECT_EQ(Wrap.smin(One),
+ ConstantRange(APInt(16, (uint16_t)INT16_MIN), APInt(16, 0xb)));
EXPECT_EQ(One.smin(One), One);
TestBinaryOpExhaustive(
@@ -1320,8 +1326,8 @@ TEST_F(ConstantRangeTest, SDiv) {
}
// If there is a non-full signed envelope, that should be the result.
- APInt SMin(Bits, Results.find_first() - Bias);
- APInt SMax(Bits, Results.find_last() - Bias);
+ APInt SMin(Bits, Results.find_first() - Bias, true);
+ APInt SMax(Bits, Results.find_last() - Bias, true);
ConstantRange Envelope = ConstantRange::getNonEmpty(SMin, SMax + 1);
if (!Envelope.isFullSet()) {
EXPECT_EQ(Envelope, CR);
@@ -1340,8 +1346,8 @@ TEST_F(ConstantRangeTest, SDiv) {
--LastPos;
}
- APInt WMax(Bits, LastNeg);
- APInt WMin(Bits, LastPos);
+ APInt WMax(Bits, LastNeg, true);
+ APInt WMin(Bits, LastPos, true);
ConstantRange Wrapped = ConstantRange::getNonEmpty(WMin, WMax + 1);
EXPECT_EQ(Wrapped, CR);
});
@@ -1394,8 +1400,8 @@ TEST_F(ConstantRangeTest, SRem) {
EXPECT_EQ(Full.srem(Full), ConstantRange(APInt::getSignedMinValue(16) + 1,
APInt::getSignedMinValue(16)));
- ConstantRange PosMod(APInt(16, 10), APInt(16, 21)); // [10, 20]
- ConstantRange NegMod(APInt(16, -20), APInt(16, -9)); // [-20, -10]
+ ConstantRange PosMod(APInt(16, 10), APInt(16, 21)); // [10, 20]
+ ConstantRange NegMod(APInt(16, -20, true), APInt(16, -9, true)); // [-20, -10]
ConstantRange IntMinMod(APInt::getSignedMinValue(16));
ConstantRange Expected(16, true);
@@ -1405,12 +1411,12 @@ TEST_F(ConstantRangeTest, SRem) {
Expected = ConstantRange(APInt(16, 0), APInt(16, 20));
EXPECT_EQ(PosLargeLHS.srem(PosMod), Expected);
EXPECT_EQ(PosLargeLHS.srem(NegMod), Expected);
- ConstantRange NegLargeLHS(APInt(16, -40), APInt(16, 1));
- Expected = ConstantRange(APInt(16, -19), APInt(16, 1));
+ ConstantRange NegLargeLHS(APInt(16, -40, true), APInt(16, 1));
+ Expected = ConstantRange(APInt(16, -19, true), APInt(16, 1));
EXPECT_EQ(NegLargeLHS.srem(PosMod), Expected);
EXPECT_EQ(NegLargeLHS.srem(NegMod), Expected);
- ConstantRange PosNegLargeLHS(APInt(16, -32), APInt(16, 38));
- Expected = ConstantRange(APInt(16, -19), APInt(16, 20));
+ ConstantRange PosNegLargeLHS(APInt(16, -32, true), APInt(16, 38));
+ Expected = ConstantRange(APInt(16, -19, true), APInt(16, 20));
EXPECT_EQ(PosNegLargeLHS.srem(PosMod), Expected);
EXPECT_EQ(PosNegLargeLHS.srem(NegMod), Expected);
@@ -1419,11 +1425,11 @@ TEST_F(ConstantRangeTest, SRem) {
EXPECT_EQ(PosLHS.srem(PosMod), PosLHS);
EXPECT_EQ(PosLHS.srem(NegMod), PosLHS);
EXPECT_EQ(PosLHS.srem(IntMinMod), PosLHS);
- ConstantRange NegLHS(APInt(16, -15), APInt(16, 1));
+ ConstantRange NegLHS(APInt(16, -15, true), APInt(16, 1));
EXPECT_EQ(NegLHS.srem(PosMod), NegLHS);
EXPECT_EQ(NegLHS.srem(NegMod), NegLHS);
EXPECT_EQ(NegLHS.srem(IntMinMod), NegLHS);
- ConstantRange PosNegLHS(APInt(16, -12), APInt(16, 18));
+ ConstantRange PosNegLHS(APInt(16, -12, true), APInt(16, 18));
EXPECT_EQ(PosNegLHS.srem(PosMod), PosNegLHS);
EXPECT_EQ(PosNegLHS.srem(NegMod), PosNegLHS);
EXPECT_EQ(PosNegLHS.srem(IntMinMod), PosNegLHS);
@@ -1433,11 +1439,11 @@ TEST_F(ConstantRangeTest, SRem) {
EXPECT_EQ(PosSmallLHS.srem(PosMod), PosSmallLHS);
EXPECT_EQ(PosSmallLHS.srem(NegMod), PosSmallLHS);
EXPECT_EQ(PosSmallLHS.srem(IntMinMod), PosSmallLHS);
- ConstantRange NegSmallLHS(APInt(16, -7), APInt(16, -2));
+ ConstantRange NegSmallLHS(APInt(16, -7, true), APInt(16, -2, true));
EXPECT_EQ(NegSmallLHS.srem(PosMod), NegSmallLHS);
EXPECT_EQ(NegSmallLHS.srem(NegMod), NegSmallLHS);
EXPECT_EQ(NegSmallLHS.srem(IntMinMod), NegSmallLHS);
- ConstantRange PosNegSmallLHS(APInt(16, -3), APInt(16, 8));
+ ConstantRange PosNegSmallLHS(APInt(16, -3, true), APInt(16, 8));
EXPECT_EQ(PosNegSmallLHS.srem(PosMod), PosNegSmallLHS);
EXPECT_EQ(PosNegSmallLHS.srem(NegMod), PosNegSmallLHS);
EXPECT_EQ(PosNegSmallLHS.srem(IntMinMod), PosNegSmallLHS);
@@ -1554,27 +1560,27 @@ TEST_F(ConstantRangeTest, ShlWithNoWrap) {
EXPECT_EQ(One.shlWithNoWrap(Full, OBO::NoSignedWrap),
ConstantRange(APInt(16, 10), APInt(16, 20481)));
EXPECT_EQ(One.shlWithNoWrap(Full, OBO::NoUnsignedWrap),
- ConstantRange(APInt(16, 10), APInt(16, -24575)));
+ ConstantRange(APInt(16, 10), APInt(16, -24575, true)));
EXPECT_EQ(One.shlWithNoWrap(Full, OBO::NoSignedWrap | OBO::NoUnsignedWrap),
ConstantRange(APInt(16, 10), APInt(16, 20481)));
ConstantRange NegOne(APInt(16, 0xffff));
EXPECT_EQ(NegOne.shlWithNoWrap(Full, OBO::NoSignedWrap),
- ConstantRange(APInt(16, -32768), APInt(16, 0)));
+ ConstantRange(APInt(16, -32768, true), APInt(16, 0)));
EXPECT_EQ(NegOne.shlWithNoWrap(Full, OBO::NoUnsignedWrap), NegOne);
EXPECT_EQ(ConstantRange(APInt(16, 768))
.shlWithNoWrap(Full, OBO::NoSignedWrap | OBO::NoUnsignedWrap),
ConstantRange(APInt(16, 768), APInt(16, 24577)));
EXPECT_EQ(Full.shlWithNoWrap(ConstantRange(APInt(16, 1), APInt(16, 16)),
OBO::NoUnsignedWrap),
- ConstantRange(APInt(16, 0), APInt(16, -1)));
- EXPECT_EQ(ConstantRange(APInt(4, 3), APInt(4, -8))
+ ConstantRange(APInt(16, 0), APInt(16, -1, true)));
+ EXPECT_EQ(ConstantRange(APInt(4, 3), APInt(4, -8, true))
.shlWithNoWrap(ConstantRange(APInt(4, 0), APInt(4, 4)),
OBO::NoSignedWrap),
- ConstantRange(APInt(4, 3), APInt(4, -8)));
- EXPECT_EQ(ConstantRange(APInt(4, -1), APInt(4, 0))
+ ConstantRange(APInt(4, 3), APInt(4, -8, true)));
+ EXPECT_EQ(ConstantRange(APInt(4, -1, true), APInt(4, 0))
.shlWithNoWrap(ConstantRange(APInt(4, 1), APInt(4, 4)),
OBO::NoSignedWrap),
- ConstantRange(APInt(4, -8), APInt(4, -1)));
+ ConstantRange(APInt(4, -8, true), APInt(4, -1, true)));
}
TEST_F(ConstantRangeTest, Lshr) {
@@ -1620,9 +1626,9 @@ TEST_F(ConstantRangeTest, Ashr) {
APInt(16, (0xaaa >> 0xa) + 1)));
EXPECT_EQ(Some.ashr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
EXPECT_EQ(Wrap.ashr(Wrap), Full);
- ConstantRange Neg(APInt(16, 0xf3f0, true), APInt(16, 0xf7f8, true));
- EXPECT_EQ(Neg.ashr(Small), ConstantRange(APInt(16, 0xfffc, true),
- APInt(16, 0xfffe, true)));
+ ConstantRange Neg(APInt(16, 0xf3f0), APInt(16, 0xf7f8));
+ EXPECT_EQ(Neg.ashr(Small),
+ ConstantRange(APInt(16, 0xfffc), APInt(16, 0xfffe)));
}
TEST(ConstantRange, MakeAllowedICmpRegion) {
@@ -1665,23 +1671,23 @@ TEST(ConstantRange, MakeSatisfyingICmpRegion) {
UnsignedSample),
ConstantRange(APInt(8, 199), APInt(8, 0)));
- ConstantRange SignedSample(APInt(8, -5), APInt(8, 5));
+ ConstantRange SignedSample(APInt(8, -5, true), APInt(8, 5));
EXPECT_EQ(
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLT, SignedSample),
- ConstantRange(APInt(8, -128), APInt(8, -5)));
+ ConstantRange(APInt(8, -128, true), APInt(8, -5, true)));
EXPECT_EQ(
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLE, SignedSample),
- ConstantRange(APInt(8, -128), APInt(8, -4)));
+ ConstantRange(APInt(8, -128, true), APInt(8, -4, true)));
EXPECT_EQ(
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGT, SignedSample),
- ConstantRange(APInt(8, 5), APInt(8, -128)));
+ ConstantRange(APInt(8, 5), APInt(8, -128, true)));
EXPECT_EQ(
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGE, SignedSample),
- ConstantRange(APInt(8, 4), APInt(8, -128)));
+ ConstantRange(APInt(8, 4), APInt(8, -128, true)));
}
void ICmpTestImpl(CmpInst::Predicate Pred) {
@@ -1703,7 +1709,7 @@ TEST(ConstantRange, ICmp) {
}
TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
- const int IntMin4Bits = 8;
+ const int IntMin4Bits = -8;
const int IntMax4Bits = 7;
typedef OverflowingBinaryOperator OBO;
@@ -1812,7 +1818,7 @@ TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
Instruction::Sub, OneToFive, OBO::NoUnsignedWrap),
ConstantRange(APInt::getMinValue(32) + 5, APInt::getMinValue(32)));
- ConstantRange MinusFiveToMinusTwo(APInt(32, -5), APInt(32, -1));
+ ConstantRange MinusFiveToMinusTwo(APInt(32, -5, true), APInt(32, -1, true));
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
Instruction::Add, MinusFiveToMinusTwo, OBO::NoSignedWrap),
ConstantRange(APInt::getSignedMinValue(32) + 5,
@@ -1826,10 +1832,9 @@ TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
APInt::getSignedMaxValue(32) - 4));
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
Instruction::Sub, MinusFiveToMinusTwo, OBO::NoUnsignedWrap),
- ConstantRange(APInt::getMaxValue(32) - 1,
- APInt::getMinValue(32)));
+ ConstantRange(APInt::getMaxValue(32) - 1, APInt::getMinValue(32)));
- ConstantRange MinusOneToOne(APInt(32, -1), APInt(32, 2));
+ ConstantRange MinusOneToOne(APInt(32, -1, true), APInt(32, 2));
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
Instruction::Add, MinusOneToOne, OBO::NoSignedWrap),
ConstantRange(APInt::getSignedMinValue(32) + 1,
@@ -1877,7 +1882,7 @@ TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
ConstantRange(APInt(32, 0), APInt(32, 1) + 1));
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
Instruction::Shl, UpToBitWidth, OBO::NoSignedWrap),
- ConstantRange(APInt(32, -1), APInt(32, 0) + 1));
+ ConstantRange(APInt(32, -1, true), APInt(32, 0) + 1));
EXPECT_EQ(
ConstantRange::makeGuaranteedNoWrapRegion(
@@ -1898,34 +1903,36 @@ TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
Instruction::Shl, IllegalShAmt, OBO::NoSignedWrap),
ConstantRange::getFull(32));
- EXPECT_EQ(
- ConstantRange::makeGuaranteedNoWrapRegion(
- Instruction::Shl, ConstantRange(APInt(32, -32), APInt(32, 16) + 1),
- OBO::NoUnsignedWrap),
- ConstantRange::makeGuaranteedNoWrapRegion(
- Instruction::Shl, ConstantRange(APInt(32, 0), APInt(32, 16) + 1),
- OBO::NoUnsignedWrap));
- EXPECT_EQ(
- ConstantRange::makeGuaranteedNoWrapRegion(
- Instruction::Shl, ConstantRange(APInt(32, -32), APInt(32, 16) + 1),
- OBO::NoSignedWrap),
- ConstantRange::makeGuaranteedNoWrapRegion(
- Instruction::Shl, ConstantRange(APInt(32, 0), APInt(32, 16) + 1),
- OBO::NoSignedWrap));
+ EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
+ Instruction::Shl,
+ ConstantRange(APInt(32, -32, true), APInt(32, 16) + 1),
+ OBO::NoUnsignedWrap),
+ ConstantRange::makeGuaranteedNoWrapRegion(
+ Instruction::Shl,
+ ConstantRange(APInt(32, 0), APInt(32, 16) + 1),
+ OBO::NoUnsignedWrap));
+ EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
+ Instruction::Shl,
+ ConstantRange(APInt(32, -32, true), APInt(32, 16) + 1),
+ OBO::NoSignedWrap),
+ ConstantRange::makeGuaranteedNoWrapRegion(
+ Instruction::Shl,
+ ConstantRange(APInt(32, 0), APInt(32, 16) + 1),
+ OBO::NoSignedWrap));
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
Instruction::Shl,
- ConstantRange(APInt(32, -32), APInt(32, 16) + 1),
+ ConstantRange(APInt(32, -32, true), APInt(32, 16) + 1),
OBO::NoUnsignedWrap),
ConstantRange(APInt(32, 0), APInt(32, 65535) + 1));
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
Instruction::Shl,
- ConstantRange(APInt(32, -32), APInt(32, 16) + 1),
+ ConstantRange(APInt(32, -32, true), APInt(32, 16) + 1),
OBO::NoSignedWrap),
- ConstantRange(APInt(32, -32768), APInt(32, 32767) + 1));
+ ConstantRange(APInt(32, -32768, true), APInt(32, 32767) + 1));
}
-template<typename Fn>
+template <typename Fn>
void TestNoWrapRegionExhaustive(Instruction::BinaryOps BinOp,
unsigned NoWrapKind, Fn OverflowFn) {
for (unsigned Bits : {1, 5}) {
@@ -2090,14 +2097,15 @@ TEST(ConstantRange, GetEquivalentICmp) {
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
EXPECT_EQ(RHS, APInt(32, 0));
- EXPECT_TRUE(ConstantRange(APInt(32, -1)).getEquivalentICmp(Pred, RHS));
+ EXPECT_TRUE(ConstantRange(APInt(32, -1, true)).getEquivalentICmp(Pred, RHS));
EXPECT_EQ(Pred, CmpInst::ICMP_EQ);
- EXPECT_EQ(RHS, APInt(32, -1));
+ EXPECT_EQ(RHS, APInt(32, -1, true));
- EXPECT_TRUE(
- ConstantRange(APInt(32, -1)).inverse().getEquivalentICmp(Pred, RHS));
+ EXPECT_TRUE(ConstantRange(APInt(32, -1, true))
+ .inverse()
+ .getEquivalentICmp(Pred, RHS));
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
- EXPECT_EQ(RHS, APInt(32, -1));
+ EXPECT_EQ(RHS, APInt(32, -1, true));
EnumerateInterestingConstantRanges([](const ConstantRange &CR) {
unsigned Bits = CR.getBitWidth();
More information about the llvm-commits
mailing list