This is an archive of the discontinued LLVM Phabricator instance.

[GISel] Don't fold convergent instruction across CFG
ClosedPublic

Authored by qcolombet on Jun 24 2022, 9:55 AM.

Details

Summary

Before merging two instructions together, GISel does some sanity checks that the folding is legal.
However that check was missing that the source of the pattern may be convergent. When the destination location is in a different basic block, the folding is invalid.

Diff Detail

Event Timeline

qcolombet created this revision.Jun 24 2022, 9:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 9:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
qcolombet requested review of this revision.Jun 24 2022, 9:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 9:55 AM
Herald added a subscriber: wdng. · View Herald Transcript

Hi @arsenm ,

Do you know if AMDGPU has any convergent instruction involved in pattern with folding?
I could use that to create a test case.

Cheers,
-Quentin

I'm not sure what context this gets called in. Maybe it's possible to hit this for DPP instructions?

llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp
63

The block based check will probably break down with convergence tokens. Could this just skip convergent altogether?

I'm not sure what context this gets called in. Maybe it's possible to hit this for DPP instructions?

This is called during instruction selection from the patterns that have been generated from SDISel.
Essentially, if you have a Pat that takes two or more instructions and fold them.

Thanks for the pointer, I'll take a look.

llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp
63

We could, but I was worried this would introduce regressions when the pattern would legitimately apply.
In particular, if we don't fold when the things are in the same block, we will regress compared to SDISel.

When the convergence tokens land (they are not landed right?), we'll have to fix SDISel, so maybe it is okay to have to fix GISel at that point?
I.e., for now let's match SDISel?

What do you think?

I'm not sure what context this gets called in. Maybe it's possible to hit this for DPP instructions?

This is called during instruction selection from the patterns that have been generated from SDISel.
Essentially, if you have a Pat that takes two or more instructions and fold them.

Thanks for the pointer, I'll take a look.

I looked and don't see anything for this. We fold all of these in separate MI passes

llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp
63

OK, I guess this can match. Basically every isConvergent check will probably be broken anyway

I looked and don't see anything for this. We fold all of these in separate MI passes

Thanks for checking @arsenm !

That means I can't produce an open source test case unfortunately then.

Are you okay with the patch as is?

arsenm accepted this revision.Jun 29 2022, 9:57 AM
This revision is now accepted and ready to land.Jun 29 2022, 9:57 AM
This revision was landed with ongoing or failed builds.Jul 1 2022, 10:24 AM
This revision was automatically updated to reflect the committed changes.