-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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 all commits
214caf4
9a1de88
71abb2b
2ab66a2
9ca3190
33373fa
b358511
a709a64
f7792d2
3e1c49d
fe8860a
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 MachineLateInstrsCleanup::removeRedundantDef(MachineInstr *MI) { | |
// and the only reg it may use is FrameReg. Typically this is an immediate | ||
// load or a load-address instruction. | ||
static bool isCandidate(const MachineInstr *MI, Register &DefedReg, | ||
Register FrameReg) { | ||
Register FrameReg, const TargetRegisterInfo *TRI) { | ||
DefedReg = MCRegister::NoRegister; | ||
bool SawStore = true; | ||
if (!MI->isSafeToMove(SawStore) || MI->isImplicitDef() || MI->isInlineAsm()) | ||
|
@@ -187,9 +187,26 @@ static bool isCandidate(const MachineInstr *MI, Register &DefedReg, | |
const MachineOperand &MO = MI->getOperand(i); | ||
if (MO.isReg()) { | ||
if (MO.isDef()) { | ||
// To get the \DefedReg value, we need to check that 1st MachineOperand | ||
// is not dead and not implicit def. | ||
// For example: | ||
// renamable $r9d = MOV32r0 implicit-def dead $eflags, implicit-def $r9 | ||
// First operand is $r9d and it is not implicit def and not dead, So | ||
// it is valid and we can use it in \DefedReg. | ||
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 | ||
// If DefedReg has a valid register, check the other operands | ||
else if (DefedReg != MCRegister::NoRegister) { | ||
// If the machineOperand is Dead and Implicit then continue | ||
// to next operand. | ||
if (MO.isDead() && MO.isImplicit()) | ||
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. 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. Machine operand has this attribute for which I am trying do the enable the optimization. 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. Implicit doesn't have any semantic meaning though; in general a generic pass shouldn't need to be aware of whether the operand is implicit or not. If it's implicit it's there for liveness tracking and you can't ignore it |
||
continue; | ||
// If the machineOperand is Implicit and alias with DefedReg then | ||
// continue to next operand. | ||
if (MO.isImplicit() && TRI->isSubRegister(MO.getReg(), DefedReg)) | ||
continue; | ||
return false; | ||
} else | ||
return false; | ||
} else if (MO.getReg() && MO.getReg() != FrameReg) | ||
return false; | ||
|
@@ -235,7 +252,7 @@ bool MachineLateInstrsCleanup::processBlock(MachineBasicBlock *MBB) { | |
} | ||
|
||
Register DefedReg; | ||
bool IsCandidate = isCandidate(&MI, DefedReg, FrameReg); | ||
bool IsCandidate = isCandidate(&MI, DefedReg, FrameReg, TRI); | ||
|
||
// Check for an earlier identical and reusable instruction. | ||
if (IsCandidate && MBBDefs.hasIdentical(DefedReg, &MI)) { | ||
|
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) { | ||
|
Large diffs are not rendered by default.
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 isnt' a /// comment, so the doxygen \ syntax won't do anything; plus I don't think it does anything for comments in the body of a function, only on the declaration