Add all constant physical registers to callee preserved masks
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Tue, 20 Sep 2022 13:42:32 +0000 (13:42 +0000)
committerAlex Richardson <alexrichardson@google.com>
Wed, 21 Sep 2022 12:50:12 +0000 (12:50 +0000)
commitb84be9f2f1acb7229e4a4fa12e0832854c22bd57
tree871327ed7bd05e2ca8021f655c7581b8260d5516
parent963287acbf42867a8f7a14b1db0043daf22174f2
Add all constant physical registers to callee preserved masks

This allows MachineCopyPropagation to eliminate copies of constant registers
such as zero registers. They were previously not being eliminated as the
check for MO.clobbersPhysReg(AvailSrc) would return true for constant
registers such as MIPS $zero.

To avoid having to manually add the zero registers to all CalleeSavedRegs
instantiations in tablegen, I instead added a new isConstant bit to the
Register and set this for MIPS, RISC-V, and AArch64 zero registers.
RegisterInfoEmitter.cpp looks at this flag and adds all constant registers
to the preserved register mask.

This may also benefit other passes but so far I have only seen differences
in MachineCopyPropagation. In the future it might make sense to generate
`isConstantPhysReg()` from this information.

Original source: https://github.com/CTSRD-CHERI/llvm-project/commit/8588d8b81458ed6d87b674893e7752e6a6915574

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D131958
llvm/test/CodeGen/AArch64/avoid-zero-copy.mir
llvm/test/CodeGen/Mips/avoid-zero-copy.mir
llvm/test/CodeGen/RISCV/double-convert.ll
llvm/utils/TableGen/RegisterInfoEmitter.cpp