Skip to content

[AIEX] Fix empty unreachable blocks surviving to assembly.#940

Draft
SagarMaheshwari99 wants to merge 1 commit intoaie-publicfrom
sagarm/fix.empty.bb
Draft

[AIEX] Fix empty unreachable blocks surviving to assembly.#940
SagarMaheshwari99 wants to merge 1 commit intoaie-publicfrom
sagarm/fix.empty.bb

Conversation

@SagarMaheshwari99
Copy link
Copy Markdown
Collaborator

BranchFolding failed to eliminate empty MBBs from unreachable IR blocks because: (1) it ran before DeadMachineInstructionElim stripped the dead instructions that made the block empty, and (2) even when it did encounter such blocks, it skipped them—empty blocks with no successors didn't match the isSuccessor(FallThrough) check, and the FallThrough == MF.end() case was an unimplemented TODO.

Fix BranchFolding to handle both cases, and add a BranchFolding run after DCE in the AIE2 pipeline so it can clean up blocks that only become empty after dead code elimination.

BranchFolding failed to eliminate empty MBBs from unreachable IR blocks
because: (1) it ran before DeadMachineInstructionElim stripped the dead
instructions that made the block empty, and (2) even when it did encounter
such blocks, it skipped them—empty blocks with no successors didn't match
the `isSuccessor(FallThrough)` check, and the `FallThrough == MF.end()`
case was an unimplemented TODO.

Fix BranchFolding to handle both cases, and add a BranchFolding run after
DCE in the AIE2 pipeline so it can clean up blocks that only become empty
after dead code elimination.
Copy link
Copy Markdown
Collaborator

@martien-de-jong martien-de-jong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it will allow linking, but I think the code will still be broken. The 'unreachable' that starts this chain of events is early in llvm code, after it has inferred that calling a function would definitely cause undefined behaviour. That unreachable leaks out through inlining.
Since the branch was definitely emitted, the block definitely existed entering the MCLayer. I would rather emit that empty unreachable block rather than remove the branch to it.

@andcarminati
Copy link
Copy Markdown
Collaborator

andcarminati commented Apr 16, 2026

We fixed the root case of the problem here: #941. Should we close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants