llc -O3 generates basic blocks that end without jump

Hello.
     I noticed that when I pass the -O3 flag to llc some of the resulting ASM basic blocks (as seen by the AsmPrinter phase and the resulting .s file) don't contain any jump, be it conditional or unconditional. For example I get this ASM .s file after running llc -O3:
       // BB#0: // %entry
         mov r0, 0
         ld_64 r1, ...
         mov r2, 256
         // Notice there is no jump
       LBB0_1: // %for.cond2.preheader
         mov r3, 0
         ...

     These are not really 2 basic blocks, so the first block without jump should be merged with the successor block (if just one successor, which is always the case as far as I can see on the tests I ran).

     Did anybody already address such correction of "malformed" basic blocks obtained with llc -O3 (or -O1/O2)? Or is there any other flag that I am missing when invoking llc?

   Thank you,
     Alex

BranchFolding will attempt to replace unconditional jumps with fallthroughs where applicable. A branch instruction is not needed at the end of a MachineBasicBlock. I’m not aware of anything that will attempt to merge these blocks into one (and I don’t see much of a reason to do this, there shouldn’t be much of difference in the final code unless maybe blocks are padded with nops for aligning them). There are a few situations where the branch label will be emitted even though there are no branches to that block. See where AsmPrinter::isBlockOnlyReachableByFallthrough is used

-Matt

Like Matt, I don't see much benefit in merging these or think they're
malformed (they're just a trivial configuration for part of the CFG).

In many cases this structure will actually be necessary since LLVM
blocks can only have one entry point. So if some other block jumps to
LBB0_1 (in your case), they have to remain separate.

Cheers.

Tim.