diff options
author | Vladimir Radosavljevic <129192835+vladimirradosavljevic@users.noreply.github.com> | 2024-10-10 16:05:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-10 18:05:42 +0400 |
commit | dabb0ddbd7a7229855156c61df1d35ad845361ac (patch) | |
tree | 9ba861e7a715be2a9b9684abf22efeb6cb9dff1e /llvm/lib/CodeGen/MachineCopyPropagation.cpp | |
parent | 0a0f100a70583725428ec317138b09f935a2b9bb (diff) | |
download | llvm-dabb0ddbd7a7229855156c61df1d35ad845361ac.zip llvm-dabb0ddbd7a7229855156c61df1d35ad845361ac.tar.gz llvm-dabb0ddbd7a7229855156c61df1d35ad845361ac.tar.bz2 |
[MCP] Skip invalidating def constant regs during forward propagation (#111129)
Before this patch, redundant COPY couldn't be removed for the following
case:
```
%reg1 = COPY %const-reg
... // There is a def of %const-reg
%reg2 = COPY killed %reg1
```
where this can be optimized to:
```
... // There is a def of %const-reg
%reg2 = COPY %const-reg
```
This patch allows for such optimization by not invalidating defined
constant registers. This is safe, as architectures like AArch64 and
RISCV replace a dead definition of a GPR with a zero constant register
for certain instructions.
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineCopyPropagation.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp index 8bcc437..fb4da2c 100644 --- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp +++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp @@ -886,8 +886,11 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) { "MachineCopyPropagation should be run after register allocation!"); if (MO.isDef() && !MO.isEarlyClobber()) { - Defs.push_back(Reg.asMCReg()); - continue; + // Skip invalidating constant registers. + if (!MRI->isConstantPhysReg(Reg)) { + Defs.push_back(Reg.asMCReg()); + continue; + } } else if (MO.readsReg()) ReadRegister(Reg.asMCReg(), MI, MO.isDebug() ? DebugUse : RegularUse); } |