[MIPS GlobalISel] Select count leading zeros
authorPetar Avramovic <Petar.Avramovic@rt-rk.com>
Mon, 27 Jan 2020 08:43:38 +0000 (09:43 +0100)
committerPetar Avramovic <Petar.Avramovic@rt-rk.com>
Mon, 27 Jan 2020 08:43:38 +0000 (09:43 +0100)
commit2b66d32f3f4c4ef144e0835029e3ddd071b6ed5a
tree8f7dc8a67ea0804d9b8750f208731d9fe581f5f7
parent941f20c3bd22f2b55815c6d5aa7914d9385fb3b3
[MIPS GlobalISel] Select count leading zeros

llvm.ctlz.<type> intrinsic has additional i1 argument is_zero_undef,
it tells whether zero as the first argument produces a defined result.
MIPS clz instruction returns 32 for zero input.
G_CTLZ is generated from llvm.ctlz.<type> (<type> <src>, i1 false)
intrinsics, clang generates these intrinsics from __builtin_clz and
__builtin_clzll.
G_CTLZ_ZERO_UNDEF can also be generated from llvm.ctlz with true as
second argument. It is also traditionally part of and many algorithms
that are now predicated on avoiding zero-value inputs.

Add narrow scalar for G_CTLZ (algorithm uses G_CTLZ_ZERO_UNDEF).
Lower G_CTLZ_ZERO_UNDEF and select G_CTLZ for MIPS32.

Differential Revision: https://reviews.llvm.org/D73214
llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
llvm/lib/Target/Mips/MipsRegisterBankInfo.cpp
llvm/test/CodeGen/Mips/GlobalISel/instruction-select/ctlz.mir [new file with mode: 0644]
llvm/test/CodeGen/Mips/GlobalISel/legalizer/ctlz.mir [new file with mode: 0644]
llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/ctlz.ll [new file with mode: 0644]
llvm/test/CodeGen/Mips/GlobalISel/regbankselect/ctlz.mir [new file with mode: 0644]