This is an archive of the discontinued LLVM Phabricator instance.

TableGen/GlobalISel: Allow output instructions with multiple defs
ClosedPublic

Authored by arsenm on Jul 13 2020, 12:00 PM.

Details

Summary

The DAG behavior allows matchching input patterns with a single result
to the first result of an output instruction that defines multiple
results. The remaining defs are implicitly dead.

This starts to fix using manual selection for AMDGPU add/sub (although
it's still needed, mostly because it's also still needed for
G_PTR_ADD).

Diff Detail

Event Timeline

arsenm created this revision.Jul 13 2020, 12:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2020, 12:00 PM
Herald added subscribers: kerbowa, tpr, rovka and 3 others. · View Herald Transcript
paquette added inline comments.Jul 14 2020, 3:34 PM
llvm/utils/TableGen/GlobalISelEmitter.cpp
4809–4811

This message is misleading with this change

arsenm updated this revision to Diff 278017.Jul 14 2020, 4:09 PM
arsenm marked an inline comment as done.

Fix error message. I'll probably be removing this check soon, since I have cases that check use_empty on the results and discard the source result

madhur13490 added inline comments.Jul 15 2020, 12:26 AM
llvm/test/TableGen/GlobalISelEmitter-output-discard.td
2

You many want to check with -optimize-match-table=true and false too.

foad added a subscriber: foad.Jul 15 2020, 2:27 AM
foad added inline comments.
llvm/utils/TableGen/GlobalISelEmitter.cpp
4352–4353

"results after the first is" is bad English. How about "any result after the first is" ?

madhur13490 added inline comments.Jul 15 2020, 12:14 PM
llvm/utils/TableGen/GlobalISelEmitter.cpp
4809

I was thinking about this for the other change. If DstI's NumDefs are less than what source pattern is defining then we can ignore the defs from source pattern. So, this error message shouldn't be there and may be we can emit a warning or something. OTOH, if it's opposite, i.e. source pattern is defining a fewer values then dstI's some value will be undefined. In any case, there need not be an error because both of these are valid some or the other backend. I am not sure what we should be doing ideally from matching perspective but both cases can occur.

paquette added inline comments.Jul 15 2020, 12:46 PM
llvm/utils/TableGen/GlobalISelEmitter.cpp
2613–2619

Are we going to need more variations on RegState in the future?

If so, maybe it'd be better to do something like the pseudocode below?

RegState = nothing
if (IsDef) {
   RegState = "RegState::Define";
   if (IsDead)
      RegState += "|RegState::Dead";
}

if (RegState != nothing)
  Table << MatchTable::NamedValue(RegState);
else
   Table << MatchTable::IntValue(0);
4351

Could you get rid of the if in the loop by doing something like this?

unsigned NumDefs = DstI->Operands.NumDefs;
if (!NumDefs)
  return InsertPt;

const CodeGenInstruction *DstI = DstMIBuilder.getCGI();
DstMIBuilder.addRenderer<CopyRenderer>(DstI->Operands[0].Name);

for (unsigned I = 1; I < NumDefs; ++I) {
  const TypeSetByHwMode &ExtTy = Dst->getExtType(I);
  ...
}

return InsertPt;
arsenm marked 4 inline comments as done.Jul 15 2020, 2:01 PM
arsenm added inline comments.
llvm/utils/TableGen/GlobalISelEmitter.cpp
2613–2619

I don't think so. I think implicit is the only other one that might make sense, but I don't think there's any contexts where the selector would need implicit virtual registers

4809

I think a warning would be counterproductive. TableGen doesn't really emit warnings. We could maybe invent some new construct to indicate explicitly discarded results, but I'm not sure what it would look like

arsenm updated this revision to Diff 278301.Jul 15 2020, 2:11 PM

Address comments

arsenm marked an inline comment as done.Jul 15 2020, 2:12 PM
arsenm added inline comments.
llvm/test/TableGen/GlobalISelEmitter-output-discard.td
2

We're not really optimizing this and adding a second set of checks increases the maintenance cost of the test

This revision is now accepted and ready to land.Jul 27 2020, 2:43 PM