This is an archive of the discontinued LLVM Phabricator instance.

[LLParser] Allow zero-input phi nodes
ClosedPublic

Authored by nikic on Aug 31 2022, 12:44 AM.

Details

Summary

Zero-input phi nodes are accepted by the verifier and bitcode reader, but currently rejected by the IR parser. Allow them there as well.

Because phi nodes must have one entry for each predecessor, such phis can only occur in blocks without predecessors, aka unreachable code.

Usually, when removing the last predecessor from a block, we also remove phi nodes in it. However, this is not possible for invalidation reasons sometimes, which is why we ended up allowing zero-entry phis at some point in the past.

I've dropped the verifier unit test, because this is now covered by the regular IR test.

This fixes at least part of https://github.com/llvm/llvm-project/issues/57446.

Diff Detail

Event Timeline

nikic created this revision.Aug 31 2022, 12:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 12:44 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Aug 31 2022, 12:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 12:44 AM
spatel accepted this revision.Aug 31 2022, 5:12 AM

LGTM - I drafted a similar patch. :)

For reference, the verifier change was 9eb2c0113dfe, and that was a follow-up to D92247 which tried to fix https://llvm.org/PR48296.

llvm/lib/AsmParser/LLParser.cpp
7012–7013

Move this error check directly after parse of Ty? That could be an independent change. It doesn't appear to have any testing currently, but I think we can trigger it with something like:

%r = phi i8* ()
This revision is now accepted and ready to land.Aug 31 2022, 5:12 AM
This revision was landed with ongoing or failed builds.Aug 31 2022, 5:24 AM
This revision was automatically updated to reflect the committed changes.