[PATCH] D78769: [AArch64][GlobalISel] Select immediate forms of compares by wiggling constants

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 16:20:16 PDT 2020


paquette created this revision.
paquette added a reviewer: aemerson.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls, rovka.

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.


https://reviews.llvm.org/D78769

Files:
  llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/select-arith-immed-compare.mir
  llvm/test/CodeGen/AArch64/GlobalISel/tbz-sgt.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78769.259743.patch
Type: text/x-patch
Size: 28843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200423/fd724db7/attachment.bin>


More information about the llvm-commits mailing list