This is an archive of the discontinued LLVM Phabricator instance.

[LoopInstSimplify] Ignore users in unreachable blocks. PR55072
ClosedPublic

Authored by mkazantsev on Apr 25 2022, 2:13 AM.

Details

Summary

Logic in this pass assumes that all users of loop instructions are
either in the same loop or are LCSSA Phis. In fact, there can also
be users in unreachable blocks that currently break assertions.
Such users don't need to go to the next round of simplifications.

Diff Detail

Event Timeline

mkazantsev created this revision.Apr 25 2022, 2:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 2:13 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
mkazantsev requested review of this revision.Apr 25 2022, 2:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 2:13 AM
fhahn accepted this revision.Apr 25 2022, 2:22 AM

LGTM, thanks! I think it would be good to remove the branch on undef, as per inline comment and possible remove some of blocks that seem unneeded.

llvm/test/Transforms/LoopInstSimplify/pr55072.ll
4–5

nit: the test shouldn't be X86 specific, can this be removed?

14–15

Avoiding switching on undef might make the test less prone to unnecessary changes in case loop-instsimplify becomes more powerful in the future.

Branch/switch on undef is UB and if the source has UB this will mean verification with tools like Alive2 will always succeed, regardless of what the result of the transform is.

14–15

Those branches look like an artifact of llvm-reduce, where it fails to remove them. Are they needed?

This revision is now accepted and ready to land.Apr 25 2022, 2:22 AM
mkazantsev added inline comments.Apr 25 2022, 3:16 AM
llvm/test/Transforms/LoopInstSimplify/pr55072.ll
4–5

I guess so. Will update the test before commiting changes.

fhahn added inline comments.Apr 25 2022, 3:40 AM
llvm/test/Transforms/LoopInstSimplify/pr55072.ll
14–15

Thanks!