[AArch64][GlobalISel] Select immediate forms of compares by wiggling constants
authorJessica Paquette <jpaquette@apple.com>
Wed, 22 Apr 2020 23:43:31 +0000 (16:43 -0700)
committerJessica Paquette <jpaquette@apple.com>
Tue, 28 Apr 2020 18:35:01 +0000 (11:35 -0700)
commit2af31b3b6552f80bb77776999fa336907adc20c5
tree1e096b978a2657e93ef587d847184da7e038828e
parentfbae153ca583588de73d8fae84ec262c24d09025
[AArch64][GlobalISel] Select immediate forms of compares by wiggling constants

Similar to code in `getAArch64Cmp` in AArch64ISelLowering.

When we get a compare against a constant, sometimes, that constant isn't valid
for selecting an immediate form.

However, sometimes, you can get a valid constant by adding 1 or subtracting 1,
and updating the condition code.

This implements the following transformations when valid:

- x slt c => x sle c - 1
- x sge c => x sgt c - 1
- x ult c => x ule c - 1
- x uge c => x ugt c - 1

- x sle c => x slt c + 1
- x sgt c => s sge c + 1
- x ule c => x ult c + 1
- x ugt c => s uge c + 1

Valid meaning the constant doesn't wrap around when we fudge it, and the result
gives us a compare which can be selected into an immediate form.

This also moves `getImmedFromMO` higher up in the file so we can use it.

Differential Revision: https://reviews.llvm.org/D78769
llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
llvm/test/CodeGen/AArch64/GlobalISel/fold-select.mir
llvm/test/CodeGen/AArch64/GlobalISel/select-arith-immed-compare.mir [new file with mode: 0644]
llvm/test/CodeGen/AArch64/GlobalISel/select-cbz.mir
llvm/test/CodeGen/AArch64/GlobalISel/tbz-sgt.mir