This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Select no-return ds_* atomic ops in tblgen.
ClosedPublic

Authored by abinavpp on Dec 16 2021, 7:36 AM.

Details

Summary

SelectionDAG relies on MachineInstr's HasPostISelHook for selecting the
no-return atomic ops. GlobalISel, at the moment, doesn't handle
HasPostISelHook.

This change adds the selection for no-return ds_* atomic ops in tblgen
so that it can work with both GlobalISel and SelectionDAG. We couldn't
add the predicates for GlobalISel in this change since there's a
restriction in the GlobalISel's tblgen back-end that disallows selecting
generic atomics ops that return with instructions that doesn't return.

We can't remove the HasPostISelHook code that selects the no return
atomic ops in SelectionDAG yet since we still need to cover selections
in FLATInstructions.td.

Diff Detail

Event Timeline

abinavpp created this revision.Dec 16 2021, 7:36 AM
abinavpp requested review of this revision.Dec 16 2021, 7:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2021, 7:36 AM
abinavpp planned changes to this revision.Dec 16 2021, 7:38 AM
abinavpp added inline comments.
llvm/lib/Target/AMDGPU/DSInstructions.td
129

This is incorrect, breaking the MC tests and might be related to the change in
SIInsertWaitcnts behaviour in some of the modified tests. How can we fix this?

foad added inline comments.Dec 16 2021, 7:43 AM
llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-atomicrmw-fadd-local.mir
21 ↗(On Diff #394881)

update_mir_test_checks has changed to using "-NEXT:" so maybe regenerate the affected files first and then rebase this patch?

Petar.Avramovic added inline comments.
llvm/lib/Target/AMDGPU/DSInstructions.td
129

// FIXME: Empty (outs) is not working in global-isel.

Check GlobalISelEmitter.cpp for:

if (DstI.Operands.NumDefs < Src->getExtTypes().size())
  return failedImport("Src pattern result has more defs than dst MI (" +
                      to_string(Src->getExtTypes().size()) + " def(s) vs " +
                      to_string(DstI.Operands.NumDefs) + " def(s))");

no ret has unused return in mir right? You want nothing in the output.

abinavpp added inline comments.Dec 17 2021, 2:42 AM
llvm/lib/Target/AMDGPU/DSInstructions.td
129

Thank you! I didn't know about the -warn-on-skipped-patterns option in
global-isel's tblgen back-end.

Along with the modified patterns in this patch, I'm seeing the "Src pattern
result has more defs than dst MI" warning for NoRtn Pats like
FlatSignedAtomicPatNoRtn, GlobalAtomicNoRtnSaddrPat etc. in FLATInstructions.td
without this patch.

In Pats, how do we specify no defs for a src PatFrag to the tblgen back-end
when we have a dst Instruction with an empty outs? The FIXME near class
DSAtomicRetPat in this change asks for the same.

abinavpp marked an inline comment as done.Dec 17 2021, 3:23 AM
abinavpp added inline comments.
llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-atomicrmw-fadd-local.mir
21 ↗(On Diff #394881)
arsenm added inline comments.Dec 17 2021, 6:28 AM
llvm/lib/Target/AMDGPU/DSInstructions.td
137

You shouldn't need to change or introduce new opcodes, we have them already

abinavpp marked an inline comment as done.Dec 19 2021, 9:46 AM
abinavpp added inline comments.
llvm/lib/Target/AMDGPU/DSInstructions.td
129

I'm not sure about the right approach here. We're trying to match generic
atomic ops (excluding store, fence etc. that doesn't return) that are defined
with return values (atomic SDNode's SDTypeProfile has 1 NumResults,
G_ATOMICRMW_* have 1 outs) to Instruction with an empty outs. I don't think
we can define no-return versions for the generic atomics ops since the
corresponding ones in the IR are return versions. Let me know if I have missed
anything here.

P.S. I'll be on vacation this week.

arsenm added inline comments.Dec 20 2021, 1:21 PM
llvm/lib/Target/AMDGPU/DSInstructions.td
129

I vaguely recall relaxing this restriction in the DAG. Would it be easier to get this working on the DAG path first, before enabling the gisel selection?

We don't need to change the generic pseudos, the selection predicate should be able to see if the uses are empty.

abinavpp updated this revision to Diff 396286.Dec 27 2021, 3:35 AM

I agree with Matt on enabling this only for SelectionDAG at the moment.

  • Rebased
  • Removed the GlobalISel predicates.
  • Added the pattern for ds_cmpst that I missed before.
  • Updated the commit message.
abinavpp retitled this revision from [WIP][AMDGPU][GlobalISel] Add patterns for no-return atomic ops with single address and data in tblgen. to [AMDGPU] Select no-return ds_* atomic ops in tblgen..Dec 27 2021, 3:38 AM
abinavpp edited the summary of this revision. (Show Details)
abinavpp marked 2 inline comments as done.
arsenm added inline comments.Feb 8 2022, 6:50 AM
llvm/lib/Target/AMDGPU/DSInstructions.td
894–895

Is this fixme relevant since you handle this case

llvm/lib/Target/AMDGPU/SIInstrInfo.td
294–298

Is this a separate cleanup?

abinavpp updated this revision to Diff 407034.Feb 8 2022, 7:47 PM
  • Removed the FIXME.
  • Reworded the GISelPredicateCode TODO.
abinavpp marked an inline comment as done.Feb 8 2022, 7:52 PM
abinavpp added inline comments.
llvm/lib/Target/AMDGPU/SIInstrInfo.td
294–298

This is required since we need the ret and noret versions of these atomic ops.

arsenm accepted this revision.Feb 9 2022, 8:56 AM
This revision is now accepted and ready to land.Feb 9 2022, 8:56 AM
This revision was landed with ongoing or failed builds.Feb 9 2022, 7:57 PM
This revision was automatically updated to reflect the committed changes.