[AArch64][GlobalISel] Introduce a new post-isel optimization pass.
authorAmara Emerson <amara@apple.com>
Wed, 14 Oct 2020 06:41:32 +0000 (23:41 -0700)
committerAmara Emerson <amara@apple.com>
Fri, 23 Oct 2020 17:18:36 +0000 (10:18 -0700)
commit0f0fd383b487e004fd616ac941307422bd09c261
tree785f490706213199a4ea45abd3056679024f89ea
parentbf44d3689a0b101914e7088b9671c90e72b8a4e8
[AArch64][GlobalISel] Introduce a new post-isel optimization pass.

There are two optimizations here:

1. Consider the following code:
 FCMPSrr %0, %1, implicit-def $nzcv
 %sel1:gpr32 = CSELWr %_, %_, 12, implicit $nzcv
 %sub:gpr32 = SUBSWrr %_, %_, implicit-def $nzcv
 FCMPSrr %0, %1, implicit-def $nzcv
 %sel2:gpr32 = CSELWr %_, %_, 12, implicit $nzcv
This kind of code where we have 2 FCMPs each feeding a CSEL can happen
when we have a single IR fcmp being used by two selects. During selection,
to ensure that there can be no clobbering of nzcv between the fcmp and the
csel, we have to generate an fcmp immediately before each csel is
selected.

However, often we can essentially CSE these together later in MachineCSE.
This doesn't work though if there are unrelated flag-setting instructions
in between the two FCMPs. In this case, the SUBS defines NZCV
but it doesn't have any users, being overwritten by the second FCMP.

Our solution here is to try to convert flag setting operations between
a interval of identical FCMPs, so that CSE will be able to eliminate one.

2. SelectionDAG imported patterns for arithmetic ops currently select the
flag-setting ops for CSE reasons, and add the implicit-def $nzcv operand
to those instructions. However if those impdef operands are not marked as
dead, the peephole optimizations are not able to optimize them into non-flag
setting variants. The optimization here is to find these dead imp-defs and
mark them as such.

This pass is only enabled when optimizations are enabled.

Differential Revision: https://reviews.llvm.org/D89415
llvm/lib/Target/AArch64/AArch64.h
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/AArch64/CMakeLists.txt
llvm/lib/Target/AArch64/GISel/AArch64PostSelectOptimize.cpp [new file with mode: 0644]
llvm/test/CodeGen/AArch64/GlobalISel/gisel-commandline-option.ll
llvm/test/CodeGen/AArch64/GlobalISel/postselectopt-dead-cc-defs-in-fcmp.mir [new file with mode: 0644]
llvm/test/CodeGen/AArch64/addsub-shifted.ll
llvm/test/CodeGen/AArch64/addsub_ext.ll
llvm/utils/gn/secondary/llvm/lib/Target/AArch64/BUILD.gn