This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] support narrow G_IMPLICIT_DEF for DstSize % NarrowSize != 0
ClosedPublic

Authored by gargaroff on Mar 23 2020, 4:33 AM.

Details

Summary

When narrowing G_IMPLICIT_DEF where the original size is not a multiple
of the narrow size, emit a smaller G_IMPLICIT_DEF and use G_ANYEXT.

To prevent a potential endless loop in the legalizer, the condition
to combine G_ANYEXT(G_IMPLICIT_DEF) is changed from isInstUnsupported
to !isInstLegal, since in this case the combine is only valid if
consequent legalization of the newly combined G_IMPLICIT_DEF does not
introduce G_ANYEXT due to narrowing.

Although this legalization for G_IMPLICIT_DEF would also be valid for
the general case, it actually caused a lot of code regressions when
tried due to superfluous COPYs and combines not getting hit anymore.

Diff Detail

Event Timeline

gargaroff created this revision.Mar 23 2020, 4:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2020, 4:33 AM

I added some test cases in db3f3f0240bb3a6c6e75a547ab7c6efeca4a81ee that this should impact, can you rebase on top of that?

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
756–757

I don't think casting the vector type to a scalar makes sense, and this should introduce a vector anyext

gargaroff marked 2 inline comments as done.

Address review comments. Rebase.

@arsenm One of the tests that you added (G_IMPLICIT_DEF s1025) produces more than 9000 lines of code before it eventually fails due to a s65600 G_MERGE_VALUES (nope, not a typo). Since I didn't think it would be feasible to have more than 18000 CHECK-lines for just one test (output slightly differs between both RUN lines), I extracted this test to an extra file and only check for the error message. I hope that is alright with you.

gargaroff added inline comments.Mar 23 2020, 10:28 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
756–757

Yeah that is a good point. Fixed it.

arsenm added inline comments.Mar 30 2020, 7:34 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
761

There's no bundle here? Why isn't this just an erase from parent?

llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def-s1025.mir
11

We should probably think about how to handle such degenerate cases, but I guess it's not critical

gargaroff updated this revision to Diff 253790.EditedMar 31 2020, 12:23 AM

fix review comments

fix review comments

gargaroff marked 3 inline comments as done.Mar 31 2020, 12:32 AM
gargaroff added inline comments.
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
761

Thanks for spotting! That was just a typo.

llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def-s1025.mir
11

If you want to I could also try and see if another legalization strategy (using G_INSERT instead of G_ANYEXT) would be preferable for this case. But the legalizer cannot possibly know which one works best for a target. Unless you let targets decide for itself (similar to how targets can override s1 constant extensions).

gargaroff updated this revision to Diff 253811.Mar 31 2020, 1:51 AM
gargaroff marked an inline comment as done.

fix unit test after rebase

arsenm added inline comments.Apr 2 2020, 9:45 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
761

Should also be eraseFromParent, not merely remove

gargaroff updated this revision to Diff 254785.Apr 3 2020, 6:54 AM

use eraseFromParent

gargaroff marked an inline comment as done.Apr 3 2020, 6:54 AM

@arsenm I know this one has been a bit messy, but is this good to go now or is there something else?

arsenm accepted this revision.Apr 7 2020, 6:15 AM
This revision is now accepted and ready to land.Apr 7 2020, 6:15 AM
gargaroff edited the summary of this revision. (Show Details)Apr 8 2020, 1:59 AM
This revision was automatically updated to reflect the committed changes.