[PATCH] D96388: [AArch64][GlobalISel] Fold G_ADD into the cset for G_ICMP

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 17:14:22 PST 2021


paquette created this revision.
paquette added a reviewer: aemerson.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls, rovka.
paquette requested review of this revision.
Herald added a project: LLVM.

When we have a G_ADD which is fed by a G_ICMP on one side, we can fold it into the cset for the G_ICMP.

e.g. Given

  %cmp = G_ICMP ... %x, %y
  %add = G_ADD %cmp, %z

We would normally emit a cmp, cset, and add.

However, `%add` is either `%z` or `%z + 1`. So, we can just use `%z` as the source of the cset rather than wzr, saving an instruction.

This would probably be cleaner in AArch64PostLegalizerLowering, but we'd need to change the way we represent G_ICMP to do that, I think. For now, it's easiest to implement in selection.

This is a 0.1% code size improvement on CTMark/pairlocalalign at -Os.

Example: https://godbolt.org/z/7KdrP8


https://reviews.llvm.org/D96388

Files:
  llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/select-cmp.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96388.322548.patch
Type: text/x-patch
Size: 5077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210210/dc340e80/attachment.bin>


More information about the llvm-commits mailing list