[GlobalISel] Add G_SBFX + G_UBFX (bitfield extraction opcodes)
authorJessica Paquette <jpaquette@apple.com>
Thu, 11 Mar 2021 23:36:01 +0000 (15:36 -0800)
committerJessica Paquette <jpaquette@apple.com>
Fri, 19 Mar 2021 21:37:19 +0000 (14:37 -0700)
commit4773dd5ba9993e127586a5e5b1993d431a47372c
tree9d27b8eeed9b30089592705880f39ac83577f5e2
parentcde203e0f9438a4bba3b9b50bd437444852b9909
[GlobalISel] Add G_SBFX + G_UBFX (bitfield extraction opcodes)

There is a bunch of similar bitfield extraction code throughout *ISelDAGToDAG.

E.g, ARMISelDAGToDAG, AArch64ISelDAGToDAG, and AMDGPUISelDAGToDAG all contain
code that matches a bitfield extract from an and + right shift.

Rather than duplicating code in the same way, this adds two opcodes:

- G_UBFX (unsigned bitfield extract)
- G_SBFX (signed bitfield extract)

They work like this

```
%x = G_UBFX %y, %lsb, %width
```

Where `lsb` and `width` are

- The least-significant bit of the extraction
- The width of the extraction

This will extract `width` bits from `%y`, starting at `lsb`. G_UBFX zero-extends
the result, while G_SBFX sign-extends the result.

This should allow us to use the combiner to match the bitfield extraction
patterns rather than duplicating pattern-matching code in each target.

Differential Revision: https://reviews.llvm.org/D98464
llvm/docs/GlobalISel/GenericOpcode.rst
llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
llvm/include/llvm/Support/TargetOpcodes.def
llvm/include/llvm/Target/GenericOpcodes.td
llvm/lib/CodeGen/MachineVerifier.cpp
llvm/test/MachineVerifier/test_g_ubfx_sbfx.mir [new file with mode: 0644]
llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp