Originally authored by @sinan
blocks reached by an explicit unconditional branch from its layout predecessor are also recognized as a fallthrough block via MachineBasicBlock::getFallThrough. For such cases, we do not need an extra unconditional branch.
If test case basic-block-sections_2.ll is run with O0, then you can see the instruction sequence like:
__cxx_global_var_init: # @__cxx_global_var_init
.cfi_startproc
# %bb.0: # %entry
pushq %rax
.cfi_def_cfa_offset 16
movl $5, %edi
callq _Z3bari
movb %al, %cl
xorl %eax, %eax
# kill: def $al killed $al killed $eax
testb $1, %cl
movb %al, 7(%rsp) # 1-byte Spill
jne __cxx_global_var_init.__part.1
jmp __cxx_global_var_init.__part.2
jmp __cxx_global_var_init.__part.1
.LBB_END0_0:
.cfi_endproc
.section .text.startup,"ax",@progbits,unique,2
__cxx_global_var_init.__part.1: # %cond.true
.cfi_startproc
.cfi_def_cfa %rsp, 16
movl $3, %edi
callq _Z3bariafter this patch, the redundant branch jmp __cxx_global_var_init.__part.1 could be removed.
__cxx_global_var_init: # @__cxx_global_var_init
.cfi_startproc
# %bb.0: # %entry
pushq %rax
.cfi_def_cfa_offset 16
movl $5, %edi
callq _Z3bari
movb %al, %cl
xorl %eax, %eax
# kill: def $al killed $al killed $eax
testb $1, %cl
movb %al, 7(%rsp) # 1-byte Spill
jne __cxx_global_var_init.__part.1
jmp __cxx_global_var_init.__part.2
.LBB_END0_0:
.cfi_endproc
.section .text.startup,"ax",@progbits,unique,2
__cxx_global_var_init.__part.1: # %cond.true
.cfi_startproc
.cfi_def_cfa %rsp, 16
movl $3, %edi
callq _Z3bariThis issue happens much more frequently when I test bb section option with AArch64.
This comment seems to be explaining something about the context in which this function is called. I suggest we remove it from here.