In block-placement pass, it will create some patterns for unconditional we can do the simple early retrun.
But the early-ret pass is before block-placement, we don't want to run it again.
This patch is to do the simple early return to optimize the blocks at the last of block-placement.
When ChainBB is unconditional branch to the TBB, and TBB has no
fallthrough predecessor and fallthrough successor, try to merge
ChainBB and TBB. This is legal under the one of following conditions:
- ChainBB is empty except for an unconditional branch.
- TBB has only one predecessor.
Below is an example
BB: | BB: XOR 3, 3, 4 | XOR 3, 3, 4 B TBB | B ChainBB ... | ... ChainBB: | ChainBB: B TBB | ADD 3, 3, 4 ... | BLR TBB: | ADD 3, 3, 4 | BLR |
This patches causes a crash because it does not take into account jump tables.
If TBB is a target of jump table you eliminate the machine basic block and jump table points to dead block now resulting in bad IR.
I guess that it was expected that ReplaceUsesOfBlockWith will do all things to replace usage of TBB but I see that it does not deal with jump tables.