summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/CodeGen/GlobalISel
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2018-11-26 11:07:02 +0000
committerDiana Picus <diana.picus@linaro.org>2018-11-26 11:07:02 +0000
commit0528e2cfb387af854f184697459d2c808a916c73 (patch)
tree53b2ba87bf1aea4e9a94ff480eb57f74e29ad5c9 /llvm/unittests/CodeGen/GlobalISel
parent30887bf6c316a75854669c0c520dceb3edfd6eae (diff)
downloadbcm5719-llvm-0528e2cfb387af854f184697459d2c808a916c73.tar.gz
bcm5719-llvm-0528e2cfb387af854f184697459d2c808a916c73.zip
[ARM GlobalISel] Support G_CTLZ and G_CTLZ_ZERO_UNDEF
We can now select CLZ via the TableGen'erated code, so support G_CTLZ and G_CTLZ_ZERO_UNDEF throughout the pipeline for types <= s32. Legalizer: If the CLZ instruction is available, use it for both G_CTLZ and G_CTLZ_ZERO_UNDEF. Otherwise, use a libcall for G_CTLZ_ZERO_UNDEF and lower G_CTLZ in terms of it. In order to achieve this we need to add support to the LegalizerHelper for the legalization of G_CTLZ_ZERO_UNDEF for s32 as a libcall (__clzsi2). We also need to allow lowering of G_CTLZ in terms of G_CTLZ_ZERO_UNDEF if that is supported as a libcall, as opposed to just if it is Legal or Custom. Due to a minor refactoring of the helper function in charge of this, we will also allow the same behaviour for G_CTTZ and G_CTPOP. This is not going to be a problem in practice since we don't yet have support for treating G_CTTZ and G_CTPOP as libcalls (not even in DAGISel). Reg bank select: Map G_CTLZ to GPR. G_CTLZ_ZERO_UNDEF should not make it to this point. Instruction select: Nothing to do. llvm-svn: 347545
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel')
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
index 0cc989be3c0..f0527611975 100644
--- a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
@@ -148,6 +148,33 @@ TEST_F(LegalizerHelperTest, LowerBitCountingCTLZ0) {
ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
}
+// CTLZ expansion in terms of CTLZ_ZERO_UNDEF if the latter is a libcall
+TEST_F(LegalizerHelperTest, LowerBitCountingCTLZLibcall) {
+ if (!TM)
+ return;
+
+ // Declare your legalization info
+ DefineLegalizerInfo(
+ A, { getActionDefinitionsBuilder(G_CTLZ_ZERO_UNDEF).libcallFor({s64}); });
+ // Build
+ auto MIBCTLZ = B.buildInstr(TargetOpcode::G_CTLZ, LLT::scalar(64), Copies[0]);
+ AInfo Info(MF->getSubtarget());
+ LegalizerHelper Helper(*MF, Info);
+ ASSERT_TRUE(Helper.lower(*MIBCTLZ, 0, LLT::scalar(64)) ==
+ LegalizerHelper::LegalizeResult::Legalized);
+
+ auto CheckStr = R"(
+ CHECK: [[CZU:%[0-9]+]]:_(s64) = G_CTLZ_ZERO_UNDEF %0
+ CHECK: [[ZERO:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
+ CHECK: [[THIRTY2:%[0-9]+]]:_(s64) = G_CONSTANT i64 64
+ CHECK: [[CMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), %0:_(s64), [[ZERO]]
+ CHECK: [[SEL:%[0-9]+]]:_(s64) = G_SELECT [[CMP]]:_(s1), [[THIRTY2]]:_, [[CZU]]
+ )";
+
+ // Check
+ ASSERT_TRUE(CheckMachineFunction(*MF, CheckStr));
+}
+
// CTLZ expansion
TEST_F(LegalizerHelperTest, LowerBitCountingCTLZ1) {
if (!TM)
OpenPOWER on IntegriCloud