[llvm] [CodeGen] Have tryToSinkCopy detect regmask clobbers just like LiveRegUnitees does (PR #88023)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 08:07:48 PDT 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/88023
>From ec242d177930fbfa782533cfaec9992d44cfd7a9 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Mon, 8 Apr 2024 11:31:07 -0400
Subject: [PATCH] [CodeGen] Have tryToSinkCopy detect regmask clobbers just
like LiveRegUnits does
Otherwise, hasRegisterDependency will just skip the regmask operands that clobber registers.
---
llvm/lib/CodeGen/MachineSink.cpp | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index c3a1d3759882d8..0a0e0fd578cacb 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -1958,27 +1958,38 @@ static bool hasRegisterDependency(MachineInstr *MI,
SmallVectorImpl<unsigned> &UsedOpsInCopy,
SmallVectorImpl<unsigned> &DefedRegsInCopy,
LiveRegUnits &ModifiedRegUnits,
- LiveRegUnits &UsedRegUnits) {
+ LiveRegUnits &UsedRegUnits,
+ const TargetRegisterInfo *TRI) {
bool HasRegDependency = false;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->getOperand(i);
+ if (MO.isRegMask()) {
+ for (unsigned U = 0, E = TRI->getNumRegUnits(); U != E; ++U) {
+ for (MCRegUnitRootIterator RootReg(U, TRI); RootReg.isValid();
+ ++RootReg) {
+ if (MO.clobbersPhysReg(*RootReg) &&
+ !UsedRegUnits.available(*RootReg)) {
+ HasRegDependency = true;
+ break;
+ }
+ DefedRegsInCopy.push_back(*RootReg);
+ }
+ }
+ }
if (!MO.isReg())
continue;
Register Reg = MO.getReg();
if (!Reg)
continue;
if (MO.isDef()) {
- if (!ModifiedRegUnits.available(Reg) || !UsedRegUnits.available(Reg)) {
+ if (!UsedRegUnits.available(Reg)) {
HasRegDependency = true;
break;
}
DefedRegsInCopy.push_back(Reg);
- // FIXME: instead of isUse(), readsReg() would be a better fix here,
- // For example, we can ignore modifications in reg with undef. However,
- // it's not perfectly clear if skipping the internal read is safe in all
- // other targets.
- } else if (MO.isUse()) {
+ // Ignore undef uses and internal reads.
+ } else if (MO.readsReg()) {
if (!ModifiedRegUnits.available(Reg)) {
HasRegDependency = true;
break;
@@ -2028,7 +2039,7 @@ bool PostRAMachineSinking::tryToSinkCopy(MachineBasicBlock &CurBB,
// Bail if we can already tell the sink would be rejected, rather
// than needlessly accumulating lots of DBG_VALUEs.
if (hasRegisterDependency(&MI, UsedOpsInCopy, DefedRegsInCopy,
- ModifiedRegUnits, UsedRegUnits)) {
+ ModifiedRegUnits, UsedRegUnits, TRI)) {
IsValid = false;
break;
}
@@ -2061,7 +2072,7 @@ bool PostRAMachineSinking::tryToSinkCopy(MachineBasicBlock &CurBB,
// Don't sink the COPY if it would violate a register dependency.
if (hasRegisterDependency(&MI, UsedOpsInCopy, DefedRegsInCopy,
- ModifiedRegUnits, UsedRegUnits)) {
+ ModifiedRegUnits, UsedRegUnits, TRI)) {
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits,
TRI);
continue;
More information about the llvm-commits
mailing list