[PATCH] D157564: [MCP] Invalidate copy for super register in copy source
Jeffrey Byrnes via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 10 18:35:32 PDT 2023
jrbyrnes updated this revision to Diff 549221.
jrbyrnes added a comment.
Convert RegsToInvalidate back to MCRegister as well.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157564/new/
https://reviews.llvm.org/D157564
Files:
llvm/lib/CodeGen/MachineCopyPropagation.cpp
llvm/test/CodeGen/AMDGPU/mcp-use-before-def.mir
Index: llvm/test/CodeGen/AMDGPU/mcp-use-before-def.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/mcp-use-before-def.mir
@@ -0,0 +1,26 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
+# RUN: llc -mtriple=amdgcn-amd-amdhsa -verify-machineinstrs -run-pass=machine-cp -o - %s | FileCheck %s
+
+# machine copy prop should not introduce use before def
+---
+name: back_copy_block
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: back_copy_block
+ ; CHECK: $vgpr20_vgpr21_vgpr22_vgpr23 = IMPLICIT_DEF
+ ; CHECK-NEXT: $vgpr10_vgpr11_vgpr12_vgpr13 = IMPLICIT_DEF
+ ; CHECK-NEXT: renamable $vgpr0_vgpr1 = V_MOV_B64_e64 killed $vgpr20_vgpr21, implicit $exec
+ ; CHECK-NEXT: renamable $vgpr20 = V_MOV_B32_e32 killed $vgpr1, implicit $exec
+ ; CHECK-NEXT: renamable $vgpr6_vgpr7_vgpr8_vgpr9 = COPY renamable $vgpr10_vgpr11_vgpr12_vgpr13
+ ; CHECK-NEXT: renamable $vgpr20 = V_MOV_B32_e32 killed $vgpr6, implicit $exec
+ ; CHECK-NEXT: S_ENDPGM 0, amdgpu_allvgprs
+ $vgpr20_vgpr21_vgpr22_vgpr23 = IMPLICIT_DEF
+ $vgpr10_vgpr11_vgpr12_vgpr13 = IMPLICIT_DEF
+ renamable $vgpr0_vgpr1 = V_MOV_B64_e64 killed renamable $vgpr20_vgpr21, implicit $exec
+ renamable $vgpr20 = V_MOV_B32_e32 killed renamable $vgpr1, implicit $exec
+ renamable $vgpr6_vgpr7_vgpr8_vgpr9 = COPY killed renamable $vgpr10_vgpr11_vgpr12_vgpr13
+ renamable $vgpr14_vgpr15 = COPY killed renamable $vgpr0_vgpr1
+ renamable $vgpr20 = V_MOV_B32_e32 killed renamable $vgpr6, implicit $exec
+ renamable $vgpr1_vgpr2_vgpr3_vgpr4 = COPY killed renamable $vgpr6_vgpr7_vgpr8_vgpr9
+ S_ENDPGM 0, amdgpu_allvgprs
+...
Index: llvm/lib/CodeGen/MachineCopyPropagation.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -134,23 +134,25 @@
const TargetInstrInfo &TII, bool UseCopyInstr) {
// Since Reg might be a subreg of some registers, only invalidate Reg is not
// enough. We have to find the COPY defines Reg or registers defined by Reg
- // and invalidate all of them.
+ // and invalidate all of them. Similarly, we must invalidate all of the
+ // the subregisters used in the source of the COPY.
SmallSet<MCRegister, 8> RegsToInvalidate;
- RegsToInvalidate.insert(Reg);
+ auto InvalidateCopy = [&](MachineInstr *MI) {
+ std::optional<DestSourcePair> CopyOperands =
+ isCopyInstr(*MI, TII, UseCopyInstr);
+ assert(CopyOperands && "Expect copy");
+
+ RegsToInvalidate.insert(CopyOperands->Destination->getReg().asMCReg());
+ RegsToInvalidate.insert(CopyOperands->Source->getReg().asMCReg());
+ };
+
for (MCRegUnit Unit : TRI.regunits(Reg)) {
auto I = Copies.find(Unit);
if (I != Copies.end()) {
- if (MachineInstr *MI = I->second.MI) {
- std::optional<DestSourcePair> CopyOperands =
- isCopyInstr(*MI, TII, UseCopyInstr);
- assert(CopyOperands && "Expect copy");
-
- RegsToInvalidate.insert(
- CopyOperands->Destination->getReg().asMCReg());
- RegsToInvalidate.insert(CopyOperands->Source->getReg().asMCReg());
- }
- RegsToInvalidate.insert(I->second.DefRegs.begin(),
- I->second.DefRegs.end());
+ if (MachineInstr *MI = I->second.MI)
+ InvalidateCopy(MI);
+ if (MachineInstr *MI = I->second.LastSeenUseInCopy)
+ InvalidateCopy(MI);
}
}
for (MCRegister InvalidReg : RegsToInvalidate)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157564.549221.patch
Type: text/x-patch
Size: 3692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230811/9cd4e695/attachment-0001.bin>
More information about the llvm-commits
mailing list