[MachineCSE] Allow PRE of instructions that read physical registers
authorJohn Brawn <john.brawn@arm.com>
Thu, 27 Oct 2022 13:14:57 +0000 (14:14 +0100)
committerJohn Brawn <john.brawn@arm.com>
Wed, 2 Nov 2022 13:53:12 +0000 (13:53 +0000)
commit88ac25b357aa2ac96fd1e44cd9fd12d2f1dd189a
treebf9e9de8c523765615bd35f449b04b0cfbcb9676
parent8f6c478fbfdd018d6f05b39e9440431c40e5bcef
[MachineCSE] Allow PRE of instructions that read physical registers

Currently MachineCSE forbids PRE when the instruction reads a physical
register. Relax this so that it's allowed when the value being read is
the same as what would be read in the place the instruction would be
hoisted to.

This is being done in preparation for adding FPCR handling to the
AArch64 backend, in order to prevent it to from worsening the
generated code, but for targets that already have a similar register
it should improve things.

This patch affects code generation in several tests. The new code
looks better except for in Thumb2/LowOverheadLoops/memcall.ll where
we perform PRE but the LowOverheadLoops transformation then undoes
it. Also in AMDGPU/selectcc-opt.ll the CHECK makes things look worse,
but actually the function as a whole is better (as a MOV is PRE'd).

Differential Revision: https://reviews.llvm.org/D136675
llvm/lib/CodeGen/MachineCSE.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/hip.extern.shared.array.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/udiv.i64.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/urem.i64.ll
llvm/test/CodeGen/AMDGPU/selectcc-opt.ll
llvm/test/CodeGen/ARM/machine-cse-cmp.ll
llvm/test/CodeGen/PowerPC/machine-cse-rm-pre.mir [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/memcall.ll