-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Codegen] Remove redundant instruction using machinelateCleanup #139716
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
214caf4
9a1de88
71abb2b
2ab66a2
9ca3190
33373fa
b358511
a709a64
f7792d2
3e1c49d
fe8860a
51ebfc5
2d09638
bee2fb4
89b97de
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 |
---|---|---|
|
@@ -186,11 +186,13 @@ static bool isCandidate(const MachineInstr *MI, Register &DefedReg, | |
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { | ||
const MachineOperand &MO = MI->getOperand(i); | ||
if (MO.isReg()) { | ||
if (MO.isDef()) { | ||
if (MO.isDef() && DefedReg == MCRegister::NoRegister) { | ||
if (i == 0 && !MO.isImplicit() && !MO.isDead()) | ||
DefedReg = MO.getReg(); | ||
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'd appreciate some comments to explain what's going on, for the existing cases and the new cases. Example: 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. Sure |
||
else | ||
return false; | ||
} else if (MI->isMoveImmediate()) { | ||
return DefedReg.isValid(); | ||
} else if (MO.getReg() && MO.getReg() != FrameReg) | ||
return false; | ||
} else if (!(MO.isImm() || MO.isCImm() || MO.isFPImm() || MO.isCPI() || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,8 +113,7 @@ define amdgpu_kernel void @stored_fi_to_fi() #0 { | |
|
||
; GCN-LABEL: {{^}}stored_fi_to_global: | ||
; GCN: buffer_store_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} | ||
; GCN: v_mov_b32_e32 [[FI:v[0-9]+]], 0{{$}} | ||
; GCN: buffer_store_dword [[FI]] | ||
Comment on lines
-116
to
-117
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. This lost the point of the 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. I will check |
||
; GCN: buffer_store_dword v{{[0-9]+}} | ||
define amdgpu_kernel void @stored_fi_to_global(ptr addrspace(1) %ptr) #0 { | ||
%tmp = alloca float, addrspace(5) | ||
store float 0.0, ptr addrspace(5) %tmp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,7 @@ done: | |
; GCN-LABEL: {{^}}test_sink_global_small_max_mubuf_offset: | ||
; GCN: s_and_saveexec_b64 | ||
; SICIVI: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:4095{{$}} | ||
; GFX9: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}} | ||
; GFX9: global_load_sbyte {{v[0-9]+}}, [[ZERO]], {{s\[[0-9]+:[0-9]+\]}} offset:4095{{$}} | ||
; GFX9: global_load_sbyte {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}} offset:4095{{$}} | ||
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. This still needs the zero check, the mov is just above here now? |
||
; GCN: {{^}}.LBB2_2: | ||
; GCN: s_or_b64 exec | ||
define amdgpu_kernel void @test_sink_global_small_max_mubuf_offset(ptr addrspace(1) %out, ptr addrspace(1) %in) { | ||
|
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.
Don't understand why this is necessary, in general this would be a malformed instruction
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.
In some case instruction's MachineOperands MO.isDef() is getting true for more than one operand. Instruction having more than one define. So it just add a check that if the DefedReg is not assigned then try to find the value of register and assign it to DefedReg. Once it is assigned, do not reassign it.
As per my understanding, in any instruction's MOs there is only def and all other are use().
Please correct me if my understanding is incorrect.
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.
Instructions can have multiple defs, but this code specifically only wants to handle instructions with a single def. This should probably early exit if it encounters a second def
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.
I have updated the patch. Please check