This is an archive of the discontinued LLVM Phabricator instance.

[BasicBlockUtils] Do not move loop metadata if outer loop header.
ClosedPublic

Authored by hgreving on May 13 2022, 11:47 AM.

Details

Summary

Fixes a bug preventing moving the loop's metadata to an outer loop's header,
which happens if the loop's exit is also the header of an outer loop.

Adds a test for above.

Fixes #55416.

Diff Detail

Event Timeline

hgreving created this revision.May 13 2022, 11:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 11:47 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
hgreving requested review of this revision.May 13 2022, 11:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 11:47 AM
hgreving retitled this revision from BasicBlockUtils] Do not move loop metadata if outer loop header. to [BasicBlockUtils] Do not move loop metadata if outer loop header..May 13 2022, 11:47 AM
hgreving updated this revision to Diff 429327.May 13 2022, 12:26 PM
hgreving updated this revision to Diff 429348.May 13 2022, 2:03 PM

Whoa another corner case.

Thanks for the patch! Makes sense, I added some suggestions with respect to the test.

llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
4

nit: this uses the legacy PM syntax, would be good to update this to use -passes=loop-simplify,

14

it would make the test a bit easier to read if the names would be a bit more descriptive, e.g. _bb7 -> loop.header, _bb6 -> loop.latch, _bb2 -> exit and so on.

Also, would it be possible to pre-commit the cleaned up test and then only include the diff caused by the patch?

Thanks for the patch! Makes sense, I added some suggestions with respect to the test.

Should be done.

hgreving updated this revision to Diff 429737.May 16 2022, 8:55 AM
hgreving marked an inline comment as done.May 16 2022, 9:00 AM

Thanks for the patch! Makes sense, I added some suggestions with respect to the test.

Should be done.

hgreving marked an inline comment as done.May 16 2022, 9:00 AM
This comment was removed by hgreving.

Friendly ping on this review.

fhahn added inline comments.May 23 2022, 3:59 AM
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
1166

So the interesting case is when the original latch is shared between multiple loops. At the moment, we move the metadata to the new latch of the outer loop. With this patch we keep it at the latch of the inneer loop, which won't be the latch of the outer loop any longer.

I am not sure if either option is more correct/better than the other.

Should we duplicate the metadata and add it to the new latches of both loops? This would be in line with the original IR, where the metadata applied to both loops.

llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
27

Ah, so the the llvm.loop metadata here applies to 2 loops. `loop.latch is shared between 2 loops.

hgreving added inline comments.May 23 2022, 7:32 AM
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
1166

You're right, I think we should copy the metadata. I will update the patch.

hgreving updated this revision to Diff 431464.May 23 2022, 1:12 PM
Meinersbur accepted this revision.May 23 2022, 1:47 PM

LGTM. Please wait for @fhahn LGTM as well.

This revision is now accepted and ready to land.May 23 2022, 1:47 PM
This revision was landed with ongoing or failed builds.May 23 2022, 4:41 PM
This revision was automatically updated to reflect the committed changes.
fhahn added a comment.May 24 2022, 4:23 AM

LGTM. Please wait for @fhahn LGTM as well.

It looks like the patch was landed but the commit message seems a bit out-of-sync with the code.it

llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
7

It would probably be good to check the while function using the auto-generation script.

LGTM. Please wait for @fhahn LGTM as well.

It looks like the patch was landed but the commit message seems a bit out-of-sync with the code.it

Sorry I missed that request, but I had left it intentionally, the patch still does not move, but copies.

It would probably be good to check the while function using the auto-generation script.

Would you like me to amend?