[PATCH] D121903: [MachineCopyPropagation] More robust isForwardableRegClassCopy
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 21 04:45:10 PDT 2022
foad updated this revision to Diff 416895.
foad added a comment.
Herald added subscribers: kerbowa, jvesely.
Rebase.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121903/new/
https://reviews.llvm.org/D121903
Files:
llvm/lib/CodeGen/MachineCopyPropagation.cpp
llvm/test/CodeGen/AMDGPU/agpr-copy-propagation.mir
Index: llvm/test/CodeGen/AMDGPU/agpr-copy-propagation.mir
===================================================================
--- llvm/test/CodeGen/AMDGPU/agpr-copy-propagation.mir
+++ llvm/test/CodeGen/AMDGPU/agpr-copy-propagation.mir
@@ -11,8 +11,8 @@
; GFX908-LABEL: name: propagate_agpr
; GFX908: renamable $agpr1 = COPY renamable $agpr0, implicit $exec
- ; GFX908-NEXT: renamable $agpr2 = COPY $agpr0, implicit $exec
- ; GFX908-NEXT: renamable $agpr3 = COPY $agpr0, implicit $exec
+ ; GFX908-NEXT: renamable $agpr2 = COPY renamable $agpr1, implicit $exec
+ ; GFX908-NEXT: renamable $agpr3 = COPY renamable $agpr2, implicit $exec
; GFX908-NEXT: S_ENDPGM 0, implicit $agpr1, implicit $agpr2, implicit $agpr3
; GFX90A-LABEL: name: propagate_agpr
; GFX90A: renamable $agpr1 = COPY renamable $agpr0, implicit $exec
Index: llvm/lib/CodeGen/MachineCopyPropagation.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -413,31 +413,6 @@
if (!UseI.isCopy())
return false;
- const TargetRegisterClass *CopySrcRC =
- TRI->getMinimalPhysRegClass(CopySrcReg);
- const TargetRegisterClass *UseDstRC =
- TRI->getMinimalPhysRegClass(UseI.getOperand(0).getReg());
- const TargetRegisterClass *CrossCopyRC = TRI->getCrossCopyRegClass(CopySrcRC);
-
- // If cross copy register class is not the same as copy source register class
- // then it is not possible to copy the register directly and requires a cross
- // register class copy. Fowarding this copy without checking register class of
- // UseDst may create additional cross register copies when expanding the copy
- // instruction in later passes.
- if (CopySrcRC != CrossCopyRC) {
- const TargetRegisterClass *CopyDstRC =
- TRI->getMinimalPhysRegClass(Copy.getOperand(0).getReg());
-
- // Check if UseDstRC matches the necessary register class to copy from
- // CopySrc's register class. If so then forwarding the copy will not
- // introduce any cross-class copys. Else if CopyDstRC matches then keep the
- // copy and do not forward. If neither UseDstRC or CopyDstRC matches then
- // we may need a cross register copy later but we do not worry about it
- // here.
- if (UseDstRC != CrossCopyRC && CopyDstRC == CrossCopyRC)
- return false;
- }
-
/// COPYs don't have register class constraints, so if the user instruction
/// is a COPY, we just try to avoid introducing additional cross-class
/// COPYs. For example:
@@ -454,13 +429,20 @@
///
/// so we have reduced the number of cross-class COPYs and potentially
/// introduced a nop COPY that can be removed.
- const TargetRegisterClass *SuperRC = UseDstRC;
- for (TargetRegisterClass::sc_iterator SuperRCI = UseDstRC->getSuperClasses();
- SuperRC; SuperRC = *SuperRCI++)
- if (SuperRC->contains(CopySrcReg))
- return true;
- return false;
+ // Allow forwarding if src and dst belong to any common class, so long as they
+ // don't belong to any (possibly smaller) common class that requires copies to
+ // go via a different class.
+ Register UseDstReg = UseI.getOperand(0).getReg();
+ bool Found = false;
+ for (const TargetRegisterClass *RC : TRI->regclasses()) {
+ if (RC->contains(CopySrcReg) && RC->contains(UseDstReg)) {
+ if (TRI->getCrossCopyRegClass(RC) != RC)
+ return false;
+ Found = true;
+ }
+ }
+ return Found;
}
/// Check that \p MI does not have implicit uses that overlap with it's \p Use
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121903.416895.patch
Type: text/x-patch
Size: 3600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220321/d3ae32c3/attachment.bin>
More information about the llvm-commits
mailing list