[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>
Thu, 27 Oct 2022 13:14:57 +0000 (14:14 +0100)
commit628467e53f4ceecd2b5f0797f07591c66d9d9d2a
tree181cedc38d4703505ce2be0e874cd518c16372ec
parent5ed5b2a28c35af9de943f2f7f17fcd9bc161a752
[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/PowerPC/machine-cse-rm-pre.mir [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/memcall.ll