Skip to content

Commit

Permalink
[PatternMatchTest] Use APInt::getAllOnes() (NFC)
Browse files Browse the repository at this point in the history
Split out from #80309 to
avoid assertion failures in the future.
  • Loading branch information
nikic committed Sep 5, 2024
1 parent 67e19e5 commit 9e9971b
Showing 1 changed file with 101 additions and 101 deletions.
202 changes: 101 additions & 101 deletions llvm/unittests/IR/PatternMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST_F(PatternMatchTest, SpecificIntEQ) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 0))
Expand All @@ -93,15 +93,15 @@ TEST_F(PatternMatchTest, SpecificIntEQ) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
.match(Zero));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
.match(One));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntNE) {
Expand All @@ -110,7 +110,7 @@ TEST_F(PatternMatchTest, SpecificIntNE) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 0))
Expand All @@ -132,15 +132,15 @@ TEST_F(PatternMatchTest, SpecificIntNE) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
.match(Zero));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
.match(One));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntUGT) {
Expand All @@ -149,7 +149,7 @@ TEST_F(PatternMatchTest, SpecificIntUGT) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 0))
Expand All @@ -171,23 +171,23 @@ TEST_F(PatternMatchTest, SpecificIntUGT) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
.match(Zero));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
.match(One));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SignbitZeroChecks) {
Type *IntTy = IRB.getInt32Ty();

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_TRUE(m_Negative().match(NegOne));
EXPECT_FALSE(m_NonNegative().match(NegOne));
Expand All @@ -211,7 +211,7 @@ TEST_F(PatternMatchTest, SpecificIntUGE) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 0))
Expand All @@ -233,15 +233,15 @@ TEST_F(PatternMatchTest, SpecificIntUGE) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
.match(Zero));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
.match(One));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntULT) {
Expand All @@ -250,7 +250,7 @@ TEST_F(PatternMatchTest, SpecificIntULT) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 0))
Expand All @@ -272,15 +272,15 @@ TEST_F(PatternMatchTest, SpecificIntULT) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
.match(Zero));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
.match(One));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntULE) {
Expand All @@ -289,7 +289,7 @@ TEST_F(PatternMatchTest, SpecificIntULE) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 0))
Expand All @@ -311,15 +311,15 @@ TEST_F(PatternMatchTest, SpecificIntULE) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
.match(Zero));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
.match(One));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntSGT) {
Expand All @@ -328,7 +328,7 @@ TEST_F(PatternMatchTest, SpecificIntSGT) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 0))
Expand All @@ -350,15 +350,15 @@ TEST_F(PatternMatchTest, SpecificIntSGT) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
.match(Zero));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
.match(One));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntSGE) {
Expand All @@ -367,7 +367,7 @@ TEST_F(PatternMatchTest, SpecificIntSGE) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 0))
Expand All @@ -389,15 +389,15 @@ TEST_F(PatternMatchTest, SpecificIntSGE) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
.match(Zero));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
.match(One));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntSLT) {
Expand All @@ -406,7 +406,7 @@ TEST_F(PatternMatchTest, SpecificIntSLT) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 0))
Expand All @@ -428,15 +428,15 @@ TEST_F(PatternMatchTest, SpecificIntSLT) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
.match(Zero));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
.match(One));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, SpecificIntSLE) {
Expand All @@ -445,7 +445,7 @@ TEST_F(PatternMatchTest, SpecificIntSLE) {

Value *Zero = ConstantInt::get(IntTy, 0);
Value *One = ConstantInt::get(IntTy, 1);
Value *NegOne = ConstantInt::get(IntTy, -1);
Value *NegOne = Constant::getAllOnesValue(IntTy);

EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 0))
Expand All @@ -467,15 +467,15 @@ TEST_F(PatternMatchTest, SpecificIntSLE) {
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 1))
.match(NegOne));

EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
.match(Zero));
EXPECT_FALSE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
.match(One));
EXPECT_TRUE(
m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
.match(NegOne));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE,
APInt::getAllOnes(BitWidth))
.match(Zero));
EXPECT_FALSE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE,
APInt::getAllOnes(BitWidth))
.match(One));
EXPECT_TRUE(m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE,
APInt::getAllOnes(BitWidth))
.match(NegOne));
}

TEST_F(PatternMatchTest, Unless) {
Expand Down

0 comments on commit 9e9971b

Please sign in to comment.