diff options
author | Kai Nacke <kai.peter.nacke@ibm.com> | 2024-01-26 09:11:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 09:11:29 -0500 |
commit | f2d0bba8748137edc46ab88babcf83ceb23f68d2 (patch) | |
tree | 3c304afa5d7d2dd5ce3d3fb88f6ea38a587a20fa /llvm/unittests/CodeGen | |
parent | bb945fcd4a54c2c8f898e2bdc0d65fae841a1909 (diff) | |
download | llvm-f2d0bba8748137edc46ab88babcf83ceb23f68d2.zip llvm-f2d0bba8748137edc46ab88babcf83ceb23f68d2.tar.gz llvm-f2d0bba8748137edc46ab88babcf83ceb23f68d2.tar.bz2 |
[GISel] Lower scalar G_SELECT in LegalizerHelper (#79342)
The LegalizerHelper only has support to lower G_SELECT with
vector operands. The approach is the same for scalar arguments,
which this PR adds.
Diffstat (limited to 'llvm/unittests/CodeGen')
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp index d7876b7..73837279 100644 --- a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp @@ -3431,6 +3431,47 @@ TEST_F(AArch64GISelMITest, LowerUDIVREM) { EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; } +// Test G_SELECT lowering. +// Note: This is for testing the legalizer, aarch64 does not lower scalar +// selects like this. +TEST_F(AArch64GISelMITest, LowerSelect) { + setUp(); + if (!TM) + GTEST_SKIP(); + + // Declare your legalization info + DefineLegalizerInfo(A, { getActionDefinitionsBuilder(G_SELECT).lower(); }); + + LLT S1 = LLT::scalar(1); + LLT S32 = LLT::scalar(32); + auto Tst = B.buildTrunc(S1, Copies[0]); + auto SrcA = B.buildTrunc(S32, Copies[1]); + auto SrcB = B.buildTrunc(S32, Copies[2]); + auto SELECT = B.buildInstr(TargetOpcode::G_SELECT, {S32}, {Tst, SrcA, SrcB}); + + AInfo Info(MF->getSubtarget()); + DummyGISelObserver Observer; + LegalizerHelper Helper(*MF, Info, Observer, B); + // Perform Legalization + EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized, + Helper.lower(*SELECT, 0, S32)); + + auto CheckStr = R"( + CHECK: [[TST:%[0-9]+]]:_(s1) = G_TRUNC + CHECK: [[TRUE:%[0-9]+]]:_(s32) = G_TRUNC + CHECK: [[FALSE:%[0-9]+]]:_(s32) = G_TRUNC + CHECK: [[MSK:%[0-9]+]]:_(s32) = G_SEXT [[TST]] + CHECK: [[M:%[0-9]+]]:_(s32) = G_CONSTANT i32 -1 + CHECK: [[NEGMSK:%[0-9]+]]:_(s32) = G_XOR [[MSK]]:_, [[M]]:_ + CHECK: [[TVAL:%[0-9]+]]:_(s32) = G_AND [[TRUE]]:_, [[MSK]]:_ + CHECK: [[FVAL:%[0-9]+]]:_(s32) = G_AND [[FALSE]]:_, [[NEGMSK]]:_ + CHECK: [[RES:%[0-9]+]]:_(s32) = G_OR [[TVAL]]:_, [[FVAL]]:_ + )"; + + // Check + EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; +} + // Test widening of G_UNMERGE_VALUES TEST_F(AArch64GISelMITest, WidenUnmerge) { setUp(); |