[llvm-dev] llc -O3 generates basic blocks that end without jump

Matt Arsenault via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 7 16:27:16 PST 2017


> On Feb 7, 2017, at 16:16, Alex Susu via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> 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
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

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


More information about the llvm-dev mailing list