How basic block layout is determined during scheduling?

Hi, guys,

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

Hi Yang,

    bnz R2, LBB0_34

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

Is the "bnz" instruction marked "isBarrier" in your TableGen files? If
so, that would mean LLVM considers fallthrough impossible and decides
it can move LBB0_33 around at will. It's still very odd that it thinks
it can put it directly before LBB0_34 though.

It would be interesting to see the blocks before and after the "Basic
block placement" pass. Running llc with -print-after-all and/or -debug
might well shed some light on what's happening.

Other possible bugs are in implementations of AnalyzeBranch,
InsertBranch or RemoveBranch. They're target callbacks LLVM uses to do
its more invasive block movement. The place to start debugging is
lib/CodeGen/MachineBlockPlacement.cpp. Something in there is probably
getting confused.

Cheers.

Tim.

Thank you very much, Tim.
I comment out “let isBarrier = 1” in the definition of the conditional branch instruction and run again, it does work.

Best regards.