[LLParser] Allow zero-input phi nodes
authorNikita Popov <npopov@redhat.com>
Wed, 31 Aug 2022 07:40:50 +0000 (09:40 +0200)
committerNikita Popov <npopov@redhat.com>
Wed, 31 Aug 2022 12:24:12 +0000 (14:24 +0200)
commit5921bc42718d3723ab2a4ba412288db51cc198b2
tree471cac9094157fb08f543e4bf8d85785bb86f444
parent12d865415ff3b9c95eaf3b3d92258d7ef77d2e76
[LLParser] Allow zero-input phi nodes

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. See 9eb2c0113dfe,
D92247 and PR48296 for context.

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.

Differential Revision: https://reviews.llvm.org/D133000
llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/zero-input-phi.ll [new file with mode: 0644]
llvm/unittests/IR/BasicBlockTest.cpp