-
Notifications
You must be signed in to change notification settings - Fork 14.3k
AMDGPU/GlobalISel: Run redundant_and combine in RegBankCombiner #112353
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,7 +178,7 @@ void CombinerHelper::replaceRegWith(MachineRegisterInfo &MRI, Register FromReg, | |
if (MRI.constrainRegAttrs(ToReg, FromReg)) | ||
MRI.replaceRegWith(FromReg, ToReg); | ||
else | ||
Builder.buildCopy(ToReg, FromReg); | ||
Builder.buildCopy(FromReg, ToReg); | ||
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. Looks backwards? Can you precommit this fix with a mir test? 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. With
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. Not sure where the register class reference came from 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. It is from weird bfe lowering, bfe sets reg clases on all its inputs as it is inst-selected in regbank-select
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. ugh, we shouldn't be directly introducing S_BFE there |
||
|
||
Observer.finishedChangingAllUsesOfReg(); | ||
} | ||
|
@@ -229,8 +229,8 @@ bool CombinerHelper::matchCombineCopy(MachineInstr &MI) { | |
void CombinerHelper::applyCombineCopy(MachineInstr &MI) { | ||
Register DstReg = MI.getOperand(0).getReg(); | ||
Register SrcReg = MI.getOperand(1).getReg(); | ||
MI.eraseFromParent(); | ||
replaceRegWith(MRI, DstReg, SrcReg); | ||
MI.eraseFromParent(); | ||
} | ||
|
||
bool CombinerHelper::matchFreezeOfSingleMaybePoisonOperand( | ||
|
@@ -379,8 +379,8 @@ void CombinerHelper::applyCombineConcatVectors(MachineInstr &MI, | |
Builder.buildUndef(NewDstReg); | ||
else | ||
Builder.buildBuildVector(NewDstReg, Ops); | ||
MI.eraseFromParent(); | ||
replaceRegWith(MRI, DstReg, NewDstReg); | ||
MI.eraseFromParent(); | ||
} | ||
|
||
bool CombinerHelper::matchCombineShuffleConcat(MachineInstr &MI, | ||
|
@@ -559,8 +559,8 @@ void CombinerHelper::applyCombineShuffleVector(MachineInstr &MI, | |
else | ||
Builder.buildMergeLikeInstr(NewDstReg, Ops); | ||
|
||
MI.eraseFromParent(); | ||
replaceRegWith(MRI, DstReg, NewDstReg); | ||
MI.eraseFromParent(); | ||
} | ||
|
||
bool CombinerHelper::matchShuffleToExtract(MachineInstr &MI) { | ||
|
@@ -2825,17 +2825,17 @@ void CombinerHelper::replaceSingleDefInstWithOperand(MachineInstr &MI, | |
Register OldReg = MI.getOperand(0).getReg(); | ||
Register Replacement = MI.getOperand(OpIdx).getReg(); | ||
assert(canReplaceReg(OldReg, Replacement, MRI) && "Cannot replace register?"); | ||
MI.eraseFromParent(); | ||
replaceRegWith(MRI, OldReg, Replacement); | ||
MI.eraseFromParent(); | ||
} | ||
|
||
void CombinerHelper::replaceSingleDefInstWithReg(MachineInstr &MI, | ||
Register Replacement) { | ||
assert(MI.getNumExplicitDefs() == 1 && "Expected one explicit def?"); | ||
Register OldReg = MI.getOperand(0).getReg(); | ||
assert(canReplaceReg(OldReg, Replacement, MRI) && "Cannot replace register?"); | ||
MI.eraseFromParent(); | ||
replaceRegWith(MRI, OldReg, Replacement); | ||
MI.eraseFromParent(); | ||
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. Why is this necessary? Isn't it better to eliminate the old use to give the replacement less work? 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. The problem is when replaceRegWith wants to insert COPY. Inset point is MI that got deleted. There are other places in this file where MI is erased after replaceRegWith |
||
} | ||
|
||
bool CombinerHelper::matchConstantLargerBitWidth(MachineInstr &MI, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 -run-pass=amdgpu-regbank-combiner -verify-machineinstrs %s -o - | FileCheck %s | ||
|
||
--- | ||
name: replaceRegWith_requires_copy | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0: | ||
liveins: $sgpr0, $vgpr0_vgpr1 | ||
|
||
; CHECK-LABEL: name: replaceRegWith_requires_copy | ||
; CHECK: liveins: $sgpr0, $vgpr0_vgpr1 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:sgpr(p1) = COPY $vgpr0_vgpr1 | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:sgpr(s32) = COPY $sgpr0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:sgpr(s32) = G_CONSTANT i32 1 | ||
; CHECK-NEXT: [[ICMP:%[0-9]+]]:sreg_32(s32) = G_ICMP intpred(ne), [[COPY1]](s32), [[C]] | ||
; CHECK-NEXT: [[COPY2:%[0-9]+]]:sgpr(s32) = COPY [[ICMP]](s32) | ||
; CHECK-NEXT: G_STORE [[COPY2]](s32), [[COPY]](p1) :: (store (s32), addrspace 1) | ||
; CHECK-NEXT: S_ENDPGM 0 | ||
%0:sgpr(p1) = COPY $vgpr0_vgpr1 | ||
%1:sgpr(s32) = COPY $sgpr0 | ||
%2:sgpr(s32) = G_CONSTANT i32 1 | ||
%3:sreg_32(s32) = G_ICMP intpred(ne), %1, %2 | ||
%4:sgpr(s32) = G_AND %3, %2 | ||
G_STORE %4(s32), %0(p1) :: (store (s32), addrspace 1) | ||
S_ENDPGM 0 | ||
... |
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.
Seems too broken for precommit.
To even get to buildCopy MI must not be deleted.
Then buildCopy(ToReg, FromReg) results in
*** Bad machine code: Reading virtual register without a def ***
Could test it just as -run-pass=amdgpu-regbank-combiner without -verify-machineinstrs but that leaves other tests broken since I have to add redundant_and.
When I try to run in other combiner there is an infinite loop on regclass to regbank copy:
Any suggestions?
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.
Should add a mir test with the funny pre-assigned class situation