GlobalISel: Improve gtest usage
Don't unnecessarily use ASSERT_*, and print the MachineFunction
on failure.
llvm-svn: 353072
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
index 913fa5f..1bb07a9 100644
--- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -137,8 +137,8 @@
auto MIBCst = B.buildConstant(LLT::scalar(64), 42);
int64_t Cst;
bool match = mi_match(MIBCst->getOperand(0).getReg(), MRI, m_ICst(Cst));
- ASSERT_TRUE(match);
- ASSERT_EQ(Cst, 42);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Cst, 42);
}
TEST(PatternMatchInstr, MatchBinaryOp) {
@@ -160,13 +160,13 @@
// Test case for no bind.
bool match =
mi_match(MIBAdd->getOperand(0).getReg(), MRI, m_GAdd(m_Reg(), m_Reg()));
- ASSERT_TRUE(match);
+ EXPECT_TRUE(match);
unsigned Src0, Src1, Src2;
match = mi_match(MIBAdd->getOperand(0).getReg(), MRI,
m_GAdd(m_Reg(Src0), m_Reg(Src1)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
- ASSERT_EQ(Src1, Copies[1]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
+ EXPECT_EQ(Src1, Copies[1]);
// Build MUL(ADD %0, %1), %2
auto MIBMul = B.buildMul(s64, MIBAdd, Copies[2]);
@@ -174,17 +174,17 @@
// Try to match MUL.
match = mi_match(MIBMul->getOperand(0).getReg(), MRI,
m_GMul(m_Reg(Src0), m_Reg(Src1)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, MIBAdd->getOperand(0).getReg());
- ASSERT_EQ(Src1, Copies[2]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, MIBAdd->getOperand(0).getReg());
+ EXPECT_EQ(Src1, Copies[2]);
// Try to match MUL(ADD)
match = mi_match(MIBMul->getOperand(0).getReg(), MRI,
m_GMul(m_GAdd(m_Reg(Src0), m_Reg(Src1)), m_Reg(Src2)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
- ASSERT_EQ(Src1, Copies[1]);
- ASSERT_EQ(Src2, Copies[2]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
+ EXPECT_EQ(Src1, Copies[1]);
+ EXPECT_EQ(Src2, Copies[2]);
// Test Commutativity.
auto MIBMul2 = B.buildMul(s64, Copies[0], B.buildConstant(s64, 42));
@@ -193,50 +193,50 @@
int64_t Cst;
match = mi_match(MIBMul2->getOperand(0).getReg(), MRI,
m_GMul(m_ICst(Cst), m_Reg(Src0)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Cst, 42);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Cst, 42);
+ EXPECT_EQ(Src0, Copies[0]);
// Make sure commutative doesn't work with something like SUB.
auto MIBSub = B.buildSub(s64, Copies[0], B.buildConstant(s64, 42));
match = mi_match(MIBSub->getOperand(0).getReg(), MRI,
m_GSub(m_ICst(Cst), m_Reg(Src0)));
- ASSERT_FALSE(match);
+ EXPECT_FALSE(match);
auto MIBFMul = B.buildInstr(TargetOpcode::G_FMUL, {s64},
{Copies[0], B.buildConstant(s64, 42)});
// Match and test commutativity for FMUL.
match = mi_match(MIBFMul->getOperand(0).getReg(), MRI,
m_GFMul(m_ICst(Cst), m_Reg(Src0)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Cst, 42);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Cst, 42);
+ EXPECT_EQ(Src0, Copies[0]);
// FSUB
auto MIBFSub = B.buildInstr(TargetOpcode::G_FSUB, {s64},
{Copies[0], B.buildConstant(s64, 42)});
match = mi_match(MIBFSub->getOperand(0).getReg(), MRI,
m_GFSub(m_Reg(Src0), m_Reg()));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
// Build AND %0, %1
auto MIBAnd = B.buildAnd(s64, Copies[0], Copies[1]);
// Try to match AND.
match = mi_match(MIBAnd->getOperand(0).getReg(), MRI,
m_GAnd(m_Reg(Src0), m_Reg(Src1)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
- ASSERT_EQ(Src1, Copies[1]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
+ EXPECT_EQ(Src1, Copies[1]);
// Build OR %0, %1
auto MIBOr = B.buildOr(s64, Copies[0], Copies[1]);
// Try to match OR.
match = mi_match(MIBOr->getOperand(0).getReg(), MRI,
m_GOr(m_Reg(Src0), m_Reg(Src1)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
- ASSERT_EQ(Src1, Copies[1]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
+ EXPECT_EQ(Src1, Copies[1]);
// Try to use the FoldableInstructionsBuilder to build binary ops.
ConstantFoldingMIRBuilder CFB(B.getState());
@@ -245,15 +245,15 @@
CFB.buildAdd(s32, CFB.buildConstant(s32, 0), CFB.buildConstant(s32, 1));
// This should be a constant now.
match = mi_match(MIBCAdd->getOperand(0).getReg(), MRI, m_ICst(Cst));
- ASSERT_TRUE(match);
- ASSERT_EQ(Cst, 1);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Cst, 1);
auto MIBCAdd1 =
CFB.buildInstr(TargetOpcode::G_ADD, {s32},
{CFB.buildConstant(s32, 0), CFB.buildConstant(s32, 1)});
// This should be a constant now.
match = mi_match(MIBCAdd1->getOperand(0).getReg(), MRI, m_ICst(Cst));
- ASSERT_TRUE(match);
- ASSERT_EQ(Cst, 1);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Cst, 1);
// Try one of the other constructors of MachineIRBuilder to make sure it's
// compatible.
@@ -264,8 +264,8 @@
{CFB1.buildConstant(s32, 1), CFB1.buildConstant(s32, 1)});
// This should be a constant now.
match = mi_match(MIBCSub->getOperand(0).getReg(), MRI, m_ICst(Cst));
- ASSERT_TRUE(match);
- ASSERT_EQ(Cst, 0);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Cst, 0);
}
TEST(PatternMatchInstr, MatchFPUnaryOp) {
@@ -290,53 +290,53 @@
// Match G_FABS.
auto MIBFabs = B.buildInstr(TargetOpcode::G_FABS, {s32}, {Copy0s32});
bool match = mi_match(MIBFabs->getOperand(0).getReg(), MRI, m_GFabs(m_Reg()));
- ASSERT_TRUE(match);
+ EXPECT_TRUE(match);
unsigned Src;
auto MIBFNeg = B.buildInstr(TargetOpcode::G_FNEG, {s32}, {Copy0s32});
match = mi_match(MIBFNeg->getOperand(0).getReg(), MRI, m_GFNeg(m_Reg(Src)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src, Copy0s32->getOperand(0).getReg());
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src, Copy0s32->getOperand(0).getReg());
match = mi_match(MIBFabs->getOperand(0).getReg(), MRI, m_GFabs(m_Reg(Src)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src, Copy0s32->getOperand(0).getReg());
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src, Copy0s32->getOperand(0).getReg());
// Build and match FConstant.
auto MIBFCst = B.buildFConstant(s32, .5);
const ConstantFP *TmpFP{};
match = mi_match(MIBFCst->getOperand(0).getReg(), MRI, m_GFCst(TmpFP));
- ASSERT_TRUE(match);
- ASSERT_TRUE(TmpFP);
+ EXPECT_TRUE(match);
+ EXPECT_TRUE(TmpFP);
APFloat APF((float).5);
auto *CFP = ConstantFP::get(Context, APF);
- ASSERT_EQ(CFP, TmpFP);
+ EXPECT_EQ(CFP, TmpFP);
// Build double float.
LLT s64 = LLT::scalar(64);
auto MIBFCst64 = B.buildFConstant(s64, .5);
const ConstantFP *TmpFP64{};
match = mi_match(MIBFCst64->getOperand(0).getReg(), MRI, m_GFCst(TmpFP64));
- ASSERT_TRUE(match);
- ASSERT_TRUE(TmpFP64);
+ EXPECT_TRUE(match);
+ EXPECT_TRUE(TmpFP64);
APFloat APF64(.5);
auto CFP64 = ConstantFP::get(Context, APF64);
- ASSERT_EQ(CFP64, TmpFP64);
- ASSERT_NE(TmpFP64, TmpFP);
+ EXPECT_EQ(CFP64, TmpFP64);
+ EXPECT_NE(TmpFP64, TmpFP);
// Build half float.
LLT s16 = LLT::scalar(16);
auto MIBFCst16 = B.buildFConstant(s16, .5);
const ConstantFP *TmpFP16{};
match = mi_match(MIBFCst16->getOperand(0).getReg(), MRI, m_GFCst(TmpFP16));
- ASSERT_TRUE(match);
- ASSERT_TRUE(TmpFP16);
+ EXPECT_TRUE(match);
+ EXPECT_TRUE(TmpFP16);
bool Ignored;
APFloat APF16(.5);
APF16.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &Ignored);
auto CFP16 = ConstantFP::get(Context, APF16);
- ASSERT_EQ(TmpFP16, CFP16);
- ASSERT_NE(TmpFP16, TmpFP);
+ EXPECT_EQ(TmpFP16, CFP16);
+ EXPECT_NE(TmpFP16, TmpFP);
}
TEST(PatternMatchInstr, MatchExtendsTrunc) {
@@ -363,36 +363,36 @@
unsigned Src0;
bool match =
mi_match(MIBTrunc->getOperand(0).getReg(), MRI, m_GTrunc(m_Reg(Src0)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
match =
mi_match(MIBAExt->getOperand(0).getReg(), MRI, m_GAnyExt(m_Reg(Src0)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, MIBTrunc->getOperand(0).getReg());
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, MIBTrunc->getOperand(0).getReg());
match = mi_match(MIBSExt->getOperand(0).getReg(), MRI, m_GSExt(m_Reg(Src0)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, MIBTrunc->getOperand(0).getReg());
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, MIBTrunc->getOperand(0).getReg());
match = mi_match(MIBZExt->getOperand(0).getReg(), MRI, m_GZExt(m_Reg(Src0)));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, MIBTrunc->getOperand(0).getReg());
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, MIBTrunc->getOperand(0).getReg());
// Match ext(trunc src)
match = mi_match(MIBAExt->getOperand(0).getReg(), MRI,
m_GAnyExt(m_GTrunc(m_Reg(Src0))));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
match = mi_match(MIBSExt->getOperand(0).getReg(), MRI,
m_GSExt(m_GTrunc(m_Reg(Src0))));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
match = mi_match(MIBZExt->getOperand(0).getReg(), MRI,
m_GZExt(m_GTrunc(m_Reg(Src0))));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
}
TEST(PatternMatchInstr, MatchSpecificType) {
@@ -414,19 +414,19 @@
LLT s64 = LLT::scalar(64);
LLT s32 = LLT::scalar(32);
auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
- ASSERT_FALSE(mi_match(MIBAdd->getOperand(0).getReg(), MRI,
+ EXPECT_FALSE(mi_match(MIBAdd->getOperand(0).getReg(), MRI,
m_GAdd(m_SpecificType(s32), m_Reg())));
- ASSERT_TRUE(mi_match(MIBAdd->getOperand(0).getReg(), MRI,
+ EXPECT_TRUE(mi_match(MIBAdd->getOperand(0).getReg(), MRI,
m_GAdd(m_SpecificType(s64), m_Reg())));
// Try to match the destination type of a bitcast.
LLT v2s32 = LLT::vector(2, 32);
auto MIBCast = B.buildCast(v2s32, Copies[0]);
- ASSERT_TRUE(
+ EXPECT_TRUE(
mi_match(MIBCast->getOperand(0).getReg(), MRI, m_GBitcast(m_Reg())));
- ASSERT_TRUE(
+ EXPECT_TRUE(
mi_match(MIBCast->getOperand(0).getReg(), MRI, m_SpecificType(v2s32)));
- ASSERT_TRUE(
+ EXPECT_TRUE(
mi_match(MIBCast->getOperand(1).getReg(), MRI, m_SpecificType(s64)));
// Build a PTRToInt and INTTOPTR and match and test them.
@@ -438,8 +438,8 @@
// match the ptrtoint(inttoptr reg)
bool match = mi_match(MIBPtrToInt->getOperand(0).getReg(), MRI,
m_GPtrToInt(m_GIntToPtr(m_Reg(Src0))));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
}
TEST(PatternMatchInstr, MatchCombinators) {
@@ -463,26 +463,26 @@
bool match =
mi_match(MIBAdd->getOperand(0).getReg(), MRI,
m_all_of(m_SpecificType(s64), m_GAdd(m_Reg(Src0), m_Reg(Src1))));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
- ASSERT_EQ(Src1, Copies[1]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
+ EXPECT_EQ(Src1, Copies[1]);
// Check for s32 (which should fail).
match =
mi_match(MIBAdd->getOperand(0).getReg(), MRI,
m_all_of(m_SpecificType(s32), m_GAdd(m_Reg(Src0), m_Reg(Src1))));
- ASSERT_FALSE(match);
+ EXPECT_FALSE(match);
match =
mi_match(MIBAdd->getOperand(0).getReg(), MRI,
m_any_of(m_SpecificType(s32), m_GAdd(m_Reg(Src0), m_Reg(Src1))));
- ASSERT_TRUE(match);
- ASSERT_EQ(Src0, Copies[0]);
- ASSERT_EQ(Src1, Copies[1]);
+ EXPECT_TRUE(match);
+ EXPECT_EQ(Src0, Copies[0]);
+ EXPECT_EQ(Src1, Copies[1]);
// Match a case where none of the predicates hold true.
match = mi_match(
MIBAdd->getOperand(0).getReg(), MRI,
m_any_of(m_SpecificType(LLT::scalar(16)), m_GSub(m_Reg(), m_Reg())));
- ASSERT_FALSE(match);
+ EXPECT_FALSE(match);
}
} // namespace