[PATCH] D108011: [MachineCopyPropagation] Check CrossCopyRegClass for cross-class copys

Vang Thao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 12 21:39:44 PDT 2021


vangthao created this revision.
Herald added subscribers: foad, kerbowa, hiraditya, tpr, nhaehnle, jvesely, arsenm.
vangthao requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

On some AMDGPU subtargets, copying to and from AGPR registers using another
AGPR register is not possible. A intermediate VGPR register is needed for AGPR
to AGPR copy. This is an issue when machine copy propagation forwards a
COPY $agpr, replacing a COPY $vgpr which results in $agpr = COPY $agpr. It is
removing a cross class copy that may have been optimized by previous passes and
potentially creating an unoptimized cross class copy later on.

To avoid this issue, check CrossCopyRegClass if a different register class will
be needed for the copy. If so then avoid forwarding the copy when the
destination does not match the desired register class and if the original copy
already matches the desired register class.

Issue seen while attempting to optimize another AGPR to AGPR issue:

Live-ins: $agpr0
$vgpr0 = COPY $agpr0
$agpr1 = V_ACCVGPR_WRITE_B32 $vgpr0
$agpr2 = COPY $vgpr0
$agpr3 = COPY $vgpr0
$agpr4 = COPY $vgpr0

After machine-cp:

$vgpr0 = COPY $agpr0
$agpr1 = V_ACCVGPR_WRITE_B32 $vgpr0
$agpr2 = COPY $agpr0
$agpr3 = COPY $agpr0
$agpr4 = COPY $agpr0

Machine-cp propagated COPY $agpr0 to replace $vgpr0 creating 3 AGPR to AGPR
copys. Later this creates a cross-register copy from AGPR->VGPR->AGPR for each
copy when the prior VGPR->AGPR copy was already optimal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108011

Files:
  llvm/lib/CodeGen/MachineCopyPropagation.cpp
  llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
  llvm/lib/Target/AMDGPU/SIRegisterInfo.h
  llvm/test/CodeGen/AMDGPU/agpr-copy-propagation.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108011.366181.patch
Type: text/x-patch
Size: 7100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210813/57c5fcd6/attachment.bin>


More information about the llvm-commits mailing list