forked from OSchip/llvm-project
GlobalISel: Improve gtest usage
Don't unnecessarily use ASSERT_*, and print the MachineFunction on failure. llvm-svn: 353072
This commit is contained in:
parent
fd3e7a9320
commit
b3e86709dc
|
@ -14,5 +14,6 @@ add_llvm_unittest(GlobalISelTests
|
|||
LegalizerHelperTest.cpp
|
||||
LegalizerInfoTest.cpp
|
||||
MachineIRBuilderTest.cpp
|
||||
GISelMITest.cpp
|
||||
PatternMatchTest.cpp
|
||||
)
|
||||
|
|
|
@ -29,35 +29,35 @@ TEST_F(GISelMITest, TestCSE) {
|
|||
unsigned AddReg = MRI->createGenericVirtualRegister(s16);
|
||||
auto MIBAddCopy =
|
||||
CSEB.buildInstr(TargetOpcode::G_ADD, {AddReg}, {MIBInput, MIBInput});
|
||||
ASSERT_EQ(MIBAddCopy->getOpcode(), TargetOpcode::COPY);
|
||||
EXPECT_EQ(MIBAddCopy->getOpcode(), TargetOpcode::COPY);
|
||||
auto MIBAdd2 =
|
||||
CSEB.buildInstr(TargetOpcode::G_ADD, {s16}, {MIBInput, MIBInput});
|
||||
ASSERT_TRUE(&*MIBAdd == &*MIBAdd2);
|
||||
EXPECT_TRUE(&*MIBAdd == &*MIBAdd2);
|
||||
auto MIBAdd4 =
|
||||
CSEB.buildInstr(TargetOpcode::G_ADD, {s16}, {MIBInput, MIBInput});
|
||||
ASSERT_TRUE(&*MIBAdd == &*MIBAdd4);
|
||||
EXPECT_TRUE(&*MIBAdd == &*MIBAdd4);
|
||||
auto MIBAdd5 =
|
||||
CSEB.buildInstr(TargetOpcode::G_ADD, {s16}, {MIBInput, MIBInput1});
|
||||
ASSERT_TRUE(&*MIBAdd != &*MIBAdd5);
|
||||
EXPECT_TRUE(&*MIBAdd != &*MIBAdd5);
|
||||
|
||||
// Try building G_CONSTANTS.
|
||||
auto MIBCst = CSEB.buildConstant(s32, 0);
|
||||
auto MIBCst1 = CSEB.buildConstant(s32, 0);
|
||||
ASSERT_TRUE(&*MIBCst == &*MIBCst1);
|
||||
EXPECT_TRUE(&*MIBCst == &*MIBCst1);
|
||||
// Try the CFing of BinaryOps.
|
||||
auto MIBCF1 = CSEB.buildInstr(TargetOpcode::G_ADD, {s32}, {MIBCst, MIBCst});
|
||||
ASSERT_TRUE(&*MIBCF1 == &*MIBCst);
|
||||
EXPECT_TRUE(&*MIBCF1 == &*MIBCst);
|
||||
|
||||
// Try out building FCONSTANTs.
|
||||
auto MIBFP0 = CSEB.buildFConstant(s32, 1.0);
|
||||
auto MIBFP0_1 = CSEB.buildFConstant(s32, 1.0);
|
||||
ASSERT_TRUE(&*MIBFP0 == &*MIBFP0_1);
|
||||
EXPECT_TRUE(&*MIBFP0 == &*MIBFP0_1);
|
||||
CSEInfo.print();
|
||||
|
||||
// Check G_UNMERGE_VALUES
|
||||
auto MIBUnmerge = CSEB.buildUnmerge({s32, s32}, Copies[0]);
|
||||
auto MIBUnmerge2 = CSEB.buildUnmerge({s32, s32}, Copies[0]);
|
||||
ASSERT_TRUE(&*MIBUnmerge == &*MIBUnmerge2);
|
||||
EXPECT_TRUE(&*MIBUnmerge == &*MIBUnmerge2);
|
||||
}
|
||||
|
||||
TEST_F(GISelMITest, TestCSEConstantConfig) {
|
||||
|
@ -77,10 +77,10 @@ TEST_F(GISelMITest, TestCSEConstantConfig) {
|
|||
auto MIBAdd1 =
|
||||
CSEB.buildInstr(TargetOpcode::G_ADD, {s16}, {MIBInput, MIBInput});
|
||||
// We should CSE constants only. Adds should not be CSEd.
|
||||
ASSERT_TRUE(MIBAdd1->getOpcode() != TargetOpcode::COPY);
|
||||
ASSERT_TRUE(&*MIBAdd1 != &*MIBAdd);
|
||||
EXPECT_TRUE(MIBAdd1->getOpcode() != TargetOpcode::COPY);
|
||||
EXPECT_TRUE(&*MIBAdd1 != &*MIBAdd);
|
||||
// We should CSE constant.
|
||||
auto MIBZeroTmp = CSEB.buildConstant(s16, 0);
|
||||
ASSERT_TRUE(&*MIBZero == &*MIBZeroTmp);
|
||||
EXPECT_TRUE(&*MIBZero == &*MIBZeroTmp);
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//===------------------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "GISelMITest.h"
|
||||
|
||||
namespace llvm {
|
||||
std::ostream &
|
||||
operator<<(std::ostream &OS, const LLT Ty) {
|
||||
std::string Repr;
|
||||
raw_string_ostream SS{Repr};
|
||||
Ty.print(SS);
|
||||
OS << SS.str();
|
||||
return OS;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &OS, const MachineFunction &MF) {
|
||||
std::string Repr;
|
||||
raw_string_ostream SS{Repr};
|
||||
MF.print(SS);
|
||||
OS << SS.str();
|
||||
return OS;
|
||||
}
|
||||
|
||||
}
|
|
@ -43,6 +43,15 @@ static inline void initLLVM() {
|
|||
initializeCodeGen(*Registry);
|
||||
}
|
||||
|
||||
// Define a printers to help debugging when things go wrong.
|
||||
namespace llvm {
|
||||
std::ostream &
|
||||
operator<<(std::ostream &OS, const LLT Ty);
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &OS, const MachineFunction &MF);
|
||||
}
|
||||
|
||||
/// Create a TargetMachine. As we lack a dedicated always available target for
|
||||
/// unittests, we go for "AArch64".
|
||||
static std::unique_ptr<LLVMTargetMachine> createTargetMachine() {
|
||||
|
|
|
@ -36,7 +36,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ0) {
|
|||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
// Perform Legalization
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -48,7 +48,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ0) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTTZ expansion in terms of CTLZ
|
||||
|
@ -67,7 +67,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ1) {
|
|||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
// Perform Legalization
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -81,7 +81,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ1) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTTZ expansion in terms of CTPOP
|
||||
|
@ -99,7 +99,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ2) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -111,7 +111,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ2) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTTZ_ZERO_UNDEF expansion in terms of CTTZ
|
||||
|
@ -129,7 +129,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ3) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTTZ, 0, LLT::scalar(64)) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -137,7 +137,7 @@ TEST_F(GISelMITest, LowerBitCountingCTTZ3) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTLZ expansion in terms of CTLZ_ZERO_UNDEF
|
||||
|
@ -155,7 +155,7 @@ TEST_F(GISelMITest, LowerBitCountingCTLZ0) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTLZ, 0, LLT::scalar(64)) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTLZ, 0, LLT::scalar(64)) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -167,7 +167,7 @@ TEST_F(GISelMITest, LowerBitCountingCTLZ0) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTLZ expansion in terms of CTLZ_ZERO_UNDEF if the latter is a libcall
|
||||
|
@ -185,7 +185,7 @@ TEST_F(GISelMITest, LowerBitCountingCTLZLibcall) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTLZ, 0, LLT::scalar(64)) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTLZ, 0, LLT::scalar(64)) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -197,7 +197,7 @@ TEST_F(GISelMITest, LowerBitCountingCTLZLibcall) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTLZ expansion
|
||||
|
@ -217,7 +217,7 @@ TEST_F(GISelMITest, LowerBitCountingCTLZ1) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.lower(*MIBCTLZ, 0, s8) ==
|
||||
EXPECT_TRUE(Helper.lower(*MIBCTLZ, 0, s8) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -237,7 +237,7 @@ TEST_F(GISelMITest, LowerBitCountingCTLZ1) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTLZ widening.
|
||||
|
@ -258,7 +258,7 @@ TEST_F(GISelMITest, WidenBitCountingCTLZ) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBCTLZ, 1, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBCTLZ, 1, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -271,7 +271,7 @@ TEST_F(GISelMITest, WidenBitCountingCTLZ) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTLZ_ZERO_UNDEF widening.
|
||||
|
@ -293,7 +293,7 @@ TEST_F(GISelMITest, WidenBitCountingCTLZZeroUndef) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBCTLZ_ZU, 1, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBCTLZ_ZU, 1, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -306,7 +306,7 @@ TEST_F(GISelMITest, WidenBitCountingCTLZZeroUndef) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTPOP widening.
|
||||
|
@ -327,7 +327,7 @@ TEST_F(GISelMITest, WidenBitCountingCTPOP) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBCTPOP, 1, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBCTPOP, 1, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -338,7 +338,7 @@ TEST_F(GISelMITest, WidenBitCountingCTPOP) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTTZ_ZERO_UNDEF widening.
|
||||
|
@ -360,7 +360,7 @@ TEST_F(GISelMITest, WidenBitCountingCTTZ_ZERO_UNDEF) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBCTTZ_ZERO_UNDEF, 1, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBCTTZ_ZERO_UNDEF, 1, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -371,7 +371,7 @@ TEST_F(GISelMITest, WidenBitCountingCTTZ_ZERO_UNDEF) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// CTTZ widening.
|
||||
|
@ -392,7 +392,7 @@ TEST_F(GISelMITest, WidenBitCountingCTTZ) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBCTTZ, 1, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBCTTZ, 1, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -405,7 +405,7 @@ TEST_F(GISelMITest, WidenBitCountingCTTZ) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
// UADDO widening.
|
||||
TEST_F(GISelMITest, WidenUADDO) {
|
||||
|
@ -427,7 +427,7 @@ TEST_F(GISelMITest, WidenUADDO) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBUAddO, 0, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBUAddO, 0, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -442,7 +442,7 @@ TEST_F(GISelMITest, WidenUADDO) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
// USUBO widening.
|
||||
|
@ -465,7 +465,7 @@ TEST_F(GISelMITest, WidenUSUBO) {
|
|||
AInfo Info(MF->getSubtarget());
|
||||
DummyGISelObserver Observer;
|
||||
LegalizerHelper Helper(*MF, Info, Observer, B);
|
||||
ASSERT_TRUE(Helper.widenScalar(*MIBUSUBO, 0, s16) ==
|
||||
EXPECT_TRUE(Helper.widenScalar(*MIBUSUBO, 0, s16) ==
|
||||
LegalizerHelper::LegalizeResult::Legalized);
|
||||
|
||||
auto CheckStr = R"(
|
||||
|
@ -480,6 +480,6 @@ TEST_F(GISelMITest, WidenUSUBO) {
|
|||
)";
|
||||
|
||||
// Check
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
|
||||
#include "llvm/CodeGen/TargetOpcodes.h"
|
||||
#include "GISelMITest.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
@ -33,15 +34,6 @@ operator<<(std::ostream &OS, const LegalizeAction Act) {
|
|||
return OS;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &OS, const llvm::LLT Ty) {
|
||||
std::string Repr;
|
||||
raw_string_ostream SS{Repr};
|
||||
Ty.print(SS);
|
||||
OS << SS.str();
|
||||
return OS;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &OS, const llvm::LegalizeActionStep Ty) {
|
||||
OS << "LegalizeActionStep(" << Ty.Action << ", " << Ty.TypeIdx << ", "
|
||||
<< Ty.NewType << ')';
|
||||
|
@ -67,28 +59,28 @@ TEST(LegalizerInfoTest, ScalarRISC) {
|
|||
|
||||
for (unsigned opcode : {G_ADD, G_SUB}) {
|
||||
// Check we infer the correct types and actually do what we're told.
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(8)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(8)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(16)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(16)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(32)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(32)}}),
|
||||
LegalizeActionStep(Legal, 0, LLT{}));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(64)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(64)}}),
|
||||
LegalizeActionStep(Legal, 0, LLT{}));
|
||||
|
||||
// Make sure the default for over-sized types applies.
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(128)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(128)}}),
|
||||
LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64)));
|
||||
// Make sure we also handle unusual sizes
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(1)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(1)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(31)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(31)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(33)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(33)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(64)));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(63)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(63)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(64)));
|
||||
ASSERT_EQ(L.getAction({opcode, {LLT::scalar(65)}}),
|
||||
EXPECT_EQ(L.getAction({opcode, {LLT::scalar(65)}}),
|
||||
LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64)));
|
||||
}
|
||||
}
|
||||
|
@ -113,18 +105,18 @@ TEST(LegalizerInfoTest, VectorRISC) {
|
|||
|
||||
// Check we infer the correct types and actually do what we're told for some
|
||||
// simple cases.
|
||||
ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 8)}}),
|
||||
EXPECT_EQ(L.getAction({G_ADD, {LLT::vector(8, 8)}}),
|
||||
LegalizeActionStep(Legal, 0, LLT{}));
|
||||
ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 7)}}),
|
||||
EXPECT_EQ(L.getAction({G_ADD, {LLT::vector(8, 7)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::vector(8, 8)));
|
||||
ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(2, 8)}}),
|
||||
EXPECT_EQ(L.getAction({G_ADD, {LLT::vector(2, 8)}}),
|
||||
LegalizeActionStep(MoreElements, 0, LLT::vector(8, 8)));
|
||||
ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(8, 32)}}),
|
||||
EXPECT_EQ(L.getAction({G_ADD, {LLT::vector(8, 32)}}),
|
||||
LegalizeActionStep(FewerElements, 0, LLT::vector(4, 32)));
|
||||
// Check a few non-power-of-2 sizes:
|
||||
ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(3, 3)}}),
|
||||
EXPECT_EQ(L.getAction({G_ADD, {LLT::vector(3, 3)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::vector(3, 8)));
|
||||
ASSERT_EQ(L.getAction({G_ADD, {LLT::vector(3, 8)}}),
|
||||
EXPECT_EQ(L.getAction({G_ADD, {LLT::vector(3, 8)}}),
|
||||
LegalizeActionStep(MoreElements, 0, LLT::vector(8, 8)));
|
||||
}
|
||||
|
||||
|
@ -144,14 +136,14 @@ TEST(LegalizerInfoTest, MultipleTypes) {
|
|||
L.computeTables();
|
||||
|
||||
// Check we infer the correct types and actually do what we're told.
|
||||
ASSERT_EQ(L.getAction({G_PTRTOINT, {s64, p0}}),
|
||||
EXPECT_EQ(L.getAction({G_PTRTOINT, {s64, p0}}),
|
||||
LegalizeActionStep(Legal, 0, LLT{}));
|
||||
|
||||
// Make sure we also handle unusual sizes
|
||||
ASSERT_EQ(
|
||||
EXPECT_EQ(
|
||||
L.getAction({G_PTRTOINT, {LLT::scalar(65), s64}}),
|
||||
LegalizeActionStep(NarrowScalar, 0, s64));
|
||||
ASSERT_EQ(
|
||||
EXPECT_EQ(
|
||||
L.getAction({G_PTRTOINT, {s64, LLT::pointer(0, 32)}}),
|
||||
LegalizeActionStep(Unsupported, 1, LLT::pointer(0, 32)));
|
||||
}
|
||||
|
@ -169,9 +161,9 @@ TEST(LegalizerInfoTest, MultipleSteps) {
|
|||
|
||||
L.computeTables();
|
||||
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(16)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(16)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(32)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(32)}}),
|
||||
LegalizeActionStep(Lower, 0, LLT::scalar(32)));
|
||||
}
|
||||
|
||||
|
@ -187,20 +179,20 @@ TEST(LegalizerInfoTest, SizeChangeStrategy) {
|
|||
|
||||
// Check we infer the correct types and actually do what we're told.
|
||||
for (unsigned Size : {1, 8, 16, 32}) {
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(Size)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(Size)}}),
|
||||
LegalizeActionStep(Legal, 0, LLT{}));
|
||||
}
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(2)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(2)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(8)));
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(7)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(7)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(8)));
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(9)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(9)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(16)));
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(17)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(17)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(31)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(31)}}),
|
||||
LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
|
||||
ASSERT_EQ(L.getAction({G_UREM, {LLT::scalar(33)}}),
|
||||
EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(33)}}),
|
||||
LegalizeActionStep(Unsupported, 0, LLT::scalar(33)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@ TEST_F(GISelMITest, TestBuildConstantFConstant) {
|
|||
CHECK: [[VEC0:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[CONST1]]:_(s32), [[CONST1]]:_(s32)
|
||||
CHECK: [[FCONST1:%[0-9]+]]:_(s32) = G_FCONSTANT double 2.000000e+00
|
||||
CHECK: [[VEC1:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[FCONST1]]:_(s32), [[FCONST1]]:_(s32)
|
||||
|
||||
)";
|
||||
|
||||
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
|
|
@ -137,8 +137,8 @@ TEST(PatternMatchInstr, MatchIntConstant) {
|
|||
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(PatternMatchInstr, MatchBinaryOp) {
|
|||
// 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 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
|
|||
// 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 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
|
|||
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 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
|
|||
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 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
|
|||
{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 @@ TEST(PatternMatchInstr, MatchFPUnaryOp) {
|
|||
// 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 @@ TEST(PatternMatchInstr, MatchExtendsTrunc) {
|
|||
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 @@ TEST(PatternMatchInstr, MatchSpecificType) {
|
|||
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 @@ TEST(PatternMatchInstr, MatchSpecificType) {
|
|||
// 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 @@ TEST(PatternMatchInstr, MatchCombinators) {
|
|||
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
|
||||
|
||||
|
|
|
@ -15,18 +15,6 @@
|
|||
|
||||
using namespace llvm;
|
||||
|
||||
// Define a pretty printer to help debugging when things go wrong.
|
||||
namespace llvm {
|
||||
std::ostream &
|
||||
operator<<(std::ostream &OS, const llvm::LLT Ty) {
|
||||
std::string Repr;
|
||||
raw_string_ostream SS{Repr};
|
||||
Ty.print(SS);
|
||||
OS << SS.str();
|
||||
return OS;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(LowLevelTypeTest, Scalar) {
|
||||
|
|
Loading…
Reference in New Issue