[ARM GlobalISel] Support G_CTLZ and G_CTLZ_ZERO_UNDEF
authorDiana Picus <diana.picus@linaro.org>
Mon, 26 Nov 2018 11:07:02 +0000 (11:07 +0000)
committerDiana Picus <diana.picus@linaro.org>
Mon, 26 Nov 2018 11:07:02 +0000 (11:07 +0000)
commit0528e2cfb387af854f184697459d2c808a916c73
tree53b2ba87bf1aea4e9a94ff480eb57f74e29ad5c9
parent30887bf6c316a75854669c0c520dceb3edfd6eae
[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
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
llvm/lib/Target/ARM/ARMRegisterBankInfo.cpp
llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-bitcounts.mir [new file with mode: 0644]
llvm/test/CodeGen/ARM/GlobalISel/arm-regbankselect.mir
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp