Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Verifier] Duplicated Predecessors of BasicBlock can pass verifier #114796

Closed
x14ngch3n opened this issue Nov 4, 2024 · 2 comments
Closed

[Verifier] Duplicated Predecessors of BasicBlock can pass verifier #114796

x14ngch3n opened this issue Nov 4, 2024 · 2 comments
Labels
accepts-invalid llvm:ir question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@x14ngch3n
Copy link

IR below is generated with LLVM-3.6, this BB (block_1645788) has three duplicated predecessors (block_1645730) and its PHINode has three duplicated incoming values ( [ %tmp41218, %block_1645730 ] ). This BB is actually a switch case, and the duplicated predecessors are where the SwitchInst is located, the duplicated predecessors is because different cases fall through the same block.

block_1645788:                                    ; preds = %bb31747, %block_164577c, %block_1645730, %block_1645730, %block_1645730
  %tmp41324 = phi i64 [ %tmp31748, %bb31747 ], [ %tmp41323, %block_164577c ], [ %tmp41218, %block_1645730 ], [ %tmp41218, %block_1645730 ], [ %tmp41218, %block_1645730 ], !asm !165
  %tmp41325 = phi i64 [ %tmp41318, %bb31747 ], [ %tmp41318, %block_164577c ], [ %tmp31712, %block_1645730 ], [ %tmp31712, %block_1645730 ], [ %tmp31712, %block_1645730 ], !asm !165
  %tmp41326 = phi i64 [ %tmp41319, %bb31747 ], [ %tmp41319, %block_164577c ], [ %tmp41105, %block_1645730 ], [ %tmp41105, %block_1645730 ], [ %tmp41105, %block_1645730 ], !asm !165
  br label %block_164578c, !asm !166

To compare, in the latest LLVM/Clang, the compiler will not generate BB with duplicated predecessors: https://godbolt.org/z/Pxond9x47

*I don't understand why this IR can pass the verifier? Why not just keep one predecessors? * In other words, when can we assume that PHI Node can only have incoming values from distinct incoming blocks (predecessors)?

@efriedma-quic
Copy link
Collaborator

The IR rule for PHI nodes is one entry per edge. If a switch has multiple cases that branch to the same block, that counts as multiple edges. So this is working as designed.

There's maybe some argument that it should be one entry per predecessor. Or that switch cases should use a different representation that doesn't require so many duplicate edges. But that's a discussion for Discourse.

@efriedma-quic efriedma-quic closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2024
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Nov 4, 2024
@x14ngch3n
Copy link
Author

Thanks for you answer, I will move the discussion to discourse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid llvm:ir question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

3 participants