-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[RegAllocBase] Produce IMPLICIT_DEF instead of COPY undef during cleanupFailedVReg #147392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrbyrnes
wants to merge
2
commits into
llvm:main
Choose a base branch
from
jrbyrnes:UndefCopyFold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+139
−5
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include "llvm/CodeGen/MachineModuleInfo.h" | ||
#include "llvm/CodeGen/MachineRegisterInfo.h" | ||
#include "llvm/CodeGen/Spiller.h" | ||
#include "llvm/CodeGen/TargetInstrInfo.h" | ||
#include "llvm/CodeGen/TargetRegisterInfo.h" | ||
#include "llvm/CodeGen/VirtRegMap.h" | ||
#include "llvm/IR/DiagnosticInfo.h" | ||
|
@@ -60,6 +61,7 @@ void RegAllocBase::init(VirtRegMap &vrm, LiveIntervals &lis, | |
LiveRegMatrix &mat) { | ||
TRI = &vrm.getTargetRegInfo(); | ||
MRI = &vrm.getRegInfo(); | ||
TII = vrm.getMachineFunction().getSubtarget().getInstrInfo(); | ||
VRM = &vrm; | ||
LIS = &lis; | ||
Matrix = &mat; | ||
|
@@ -167,9 +169,15 @@ void RegAllocBase::cleanupFailedVReg(Register FailedReg, MCRegister PhysReg, | |
// We still should produce valid IR. Kill all the uses and reduce the live | ||
// ranges so that we don't think it's possible to introduce kill flags later | ||
// which will fail the verifier. | ||
|
||
SmallVector<MachineInstr *, 4> UndefCopies; | ||
|
||
for (MachineOperand &MO : MRI->reg_operands(FailedReg)) { | ||
if (MO.readsReg()) | ||
if (MO.readsReg()) { | ||
MO.setIsUndef(true); | ||
if (MO.getParent()->isCopy() && MO.isUse()) | ||
UndefCopies.push_back(MO.getParent()); | ||
} | ||
} | ||
|
||
if (!MRI->isReserved(PhysReg)) { | ||
|
@@ -180,12 +188,22 @@ void RegAllocBase::cleanupFailedVReg(Register FailedReg, MCRegister PhysReg, | |
for (MachineOperand &MO : MRI->reg_operands(*Aliases)) { | ||
if (MO.readsReg()) { | ||
MO.setIsUndef(true); | ||
if (MO.getParent()->isCopy() && MO.isUse()) | ||
UndefCopies.push_back(MO.getParent()); | ||
LIS->removeAllRegUnitsForPhysReg(MO.getReg()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// If we have produced an undef copy, convert to IMPLICIT_DEF. | ||
for (MachineInstr *UndefCopy : UndefCopies) { | ||
assert(UndefCopy->isCopy() && UndefCopy->getNumOperands() == 2); | ||
const MCInstrDesc &Desc = TII->get(TargetOpcode::IMPLICIT_DEF); | ||
UndefCopy->removeOperand(1); | ||
UndefCopy->setDesc(Desc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this to be the cleanest implementation for dealing with COPY bundles |
||
} | ||
|
||
// Directly perform the rewrite, and do not leave it to VirtRegRewriter as | ||
// usual. This avoids trying to manage illegal overlapping assignments in | ||
// LiveRegMatrix. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# RUN: not llc -mtriple=amdgcn -mcpu=gfx908 -verify-machineinstrs -start-before=greedy,1 -stop-after=virtregrewriter,2 -o - -verify-regalloc %s 2> %t.err | FileCheck %s | ||
# RUN: FileCheck -check-prefix=ERR %s < %t.err | ||
|
||
# Make sure there's no machine verifier error after failure. | ||
|
||
# ERR: error: inline assembly requires more registers than available | ||
# ERR: error: inline assembly requires more registers than available | ||
# ERR: error: inline assembly requires more registers than available | ||
# ERR: error: inline assembly requires more registers than available | ||
|
||
# This testcase cannot be compiled with the enforced register | ||
# budget. Previously, tryLastChanceRecoloring would assert here. It | ||
# was attempting to recolor a superregister with an overlapping | ||
# subregister over the same range. | ||
|
||
--- | | ||
define void @dead_copy() #0 { | ||
ret void | ||
} | ||
|
||
define void @copy_kill() #0 { | ||
ret void | ||
} | ||
|
||
define void @copy_subreg() #0 { | ||
ret void | ||
} | ||
|
||
define void @copy_subreg2() #0 { | ||
ret void | ||
} | ||
|
||
attributes #0 = { "amdgpu-num-vgpr"="6" } | ||
|
||
... | ||
|
||
# CHECK-LABEL: name: dead_copy | ||
# CHECK: renamable $agpr0_agpr1_agpr2 = IMPLICIT_DEF | ||
# CHECK: dead renamable $vgpr0_vgpr1_vgpr2 = COPY renamable $agpr0_agpr1_agpr2 | ||
|
||
--- | ||
name: dead_copy | ||
tracksRegLiveness: true | ||
machineFunctionInfo: | ||
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3' | ||
frameOffsetReg: '$sgpr33' | ||
stackPtrOffsetReg: '$sgpr32' | ||
body: | | ||
bb.0: | ||
|
||
INLINEASM &"; def $0 $1 $2 $3 $4", 1 /* sideeffect attdialect */, 11534346 /* regdef:VReg_512 */, def %0:vreg_512, 10158090 /* regdef:VReg_256 */, def %1:vreg_256, 4784138 /* regdef:VReg_128 */, def %2:vreg_128, 3670026 /* regdef:VReg_96 */, def %3:vreg_96, 3670026 /* regdef:VReg_96 */, def %4:vreg_96 | ||
%5:vreg_96 = COPY %3 | ||
INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 3670025 /* reguse:VReg_96 */, %3 | ||
SI_RETURN | ||
|
||
... | ||
|
||
|
||
# CHECK-LABEL: name: copy_kill | ||
# CHECK: renamable $vgpr0_vgpr1_vgpr2 = IMPLICIT_DEF | ||
|
||
--- | ||
name: copy_kill | ||
tracksRegLiveness: true | ||
machineFunctionInfo: | ||
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3' | ||
frameOffsetReg: '$sgpr33' | ||
stackPtrOffsetReg: '$sgpr32' | ||
body: | | ||
bb.0: | ||
|
||
INLINEASM &"; def $0 $1 $2 $3 $4", 1 /* sideeffect attdialect */, 11534346 /* regdef:VReg_512 */, def %0:vreg_512, 10158090 /* regdef:VReg_256 */, def %1:vreg_256, 4784138 /* regdef:VReg_128 */, def %2:vreg_128, 3670026 /* regdef:VReg_96 */, def %3:vreg_96, 3670026 /* regdef:VReg_96 */, def %4:vreg_96 | ||
%5:vreg_96 = COPY %3 | ||
INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 3670025 /* reguse:VReg_96 */, %5 | ||
SI_RETURN | ||
... | ||
|
||
# CHECK-LABEL: name: copy_subreg | ||
# CHECK: renamable $vgpr1_vgpr2 = IMPLICIT_DEF | ||
# CHECK: renamable $vgpr0 = COPY renamable $vgpr1 | ||
--- | ||
name: copy_subreg | ||
tracksRegLiveness: true | ||
machineFunctionInfo: | ||
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3' | ||
frameOffsetReg: '$sgpr33' | ||
stackPtrOffsetReg: '$sgpr32' | ||
body: | | ||
bb.0: | ||
|
||
INLINEASM &"; def $0 $1 $2 $3 $4", 1 /* sideeffect attdialect */, 11534346 /* regdef:VReg_512 */, def %0:vreg_512, 10158090 /* regdef:VReg_256 */, def %1:vreg_256, 4784138 /* regdef:VReg_128 */, def %2:vreg_128, 3670026 /* regdef:VReg_96 */, def %3:vreg_96, 3670026 /* regdef:VReg_96 */, def %4:vreg_96 | ||
%3.sub0 = COPY %3.sub1 | ||
INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 3670025 /* reguse:VReg_96 */, %3 | ||
SI_RETURN | ||
... | ||
|
||
# CHECK-LABEL: name: copy_subreg2 | ||
# CHECK: renamable $vgpr0_vgpr1_vgpr2 = IMPLICIT_DEF | ||
|
||
--- | ||
name: copy_subreg2 | ||
tracksRegLiveness: true | ||
machineFunctionInfo: | ||
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3' | ||
frameOffsetReg: '$sgpr33' | ||
stackPtrOffsetReg: '$sgpr32' | ||
body: | | ||
bb.0: | ||
|
||
INLINEASM &"; def $0 $1 $2 $3 $4", 1 /* sideeffect attdialect */, 11534346 /* regdef:VReg_512 */, def %0:vreg_512, 10158090 /* regdef:VReg_256 */, def %1:vreg_256, 4784138 /* regdef:VReg_128 */, def %2:vreg_128, 3670026 /* regdef:VReg_96 */, def %3:vreg_96, 3670026 /* regdef:VReg_96 */, def %4:vreg_96 | ||
undef %5.sub0:vreg_96 = COPY %3.sub0 | ||
%5.sub1_sub2:vreg_96 = COPY %3.sub1_sub2 | ||
INLINEASM &"; use $0", 1 /* sideeffect attdialect */, 3670025 /* reguse:VReg_96 */, %5 | ||
SI_RETURN | ||
... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert probably doesn't hold in general