[LLVMdev] How basic block layout is determined during scheduling?

杨勇勇 triple.yang at gmail.com
Wed Sep 18 04:03:32 PDT 2013


Hi, guys,

I compiled a subroutine with -O2, and llvm backend produced codes like:

##################################################################
LBB0_32:
    ...
    R31 = -1
    R20 = R31 * R20;
    ....
    bnz  R2, LBB0_34
LBB0_31:
    ...
    b  LBB0_34
LBB0_33:                  # weird basic block?
    R20 = R5
LBB0_34:
    ....
##################################################################

Wrong answer is produced when executing bove codes. LBB0_33 is not used as
destination basic block for any branch instruction, so its a dead basic
block. Original C source codes need "R20 = R5" to restore its old value if
"bnz  R2, LBB0_34" does not change control flow.

So if I move LBB0_33 just after LBB0_32 as follows:

##################################################################
LBB0_32:
    ...
    R31 = -1
    R20 = R31 * R20;
    ....
    bnz  R2, LBB0_34

LBB0_33:
    R20 = R5

LBB0_31:
    ...
    b  LBB0_34

#LBB0_33:                  # weird basic block?
#    R20 = R5

LBB0_34:
    ....
##################################################################

Resulting codes are correct. If I compile original subroutine with -O0,
result codes are also right.

I do not have any clue what happens when compiling with -O2.
Can someone make a suggestion?

-- 
杨勇勇 (Yang Yong-Yong)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130918/80fb3ac4/attachment.html>


More information about the llvm-dev mailing list