This is an issue found when testing PowerPC with verify-machineinstrs.
llc -mtriple=powerpc64-unknown-linux-gnu < llvm/llvm/test/CodeGen/PowerPC/sj-ctr-loop.ll -verify-machineinstrs
Bad machine code: MBB exits via unconditional fall-through but ends with a barrier instruction! *** function: main basic block: %bb.2 for.body.lr.ph (0x100275437e8)
Content in block BB.2:
BB#2: derived from LLVM BB %for.end Predecessors according to CFG: BB#1 %vreg2<def> = ADDIStocHA %X2, <ga:@env_sigill>; G8RC_and_G8RC_NOX0:%vreg2 %vreg3<def> = LDtocL <ga:@env_sigill>, %vreg2<kill>; mem:LD8[GOT] G8RC:%vreg3 G8RC_and_G8RC_NOX0:%vreg2 %vreg4<def> = EH_SjLj_SetJmp64 %vreg3<kill>, %CTR8<imp-def,dead>; GPRC:%vreg4 G8RC:%vreg3
A barrier instruction means control flow can not fall through like llvm.eh.sjlj.longjmp and unconditional jumps. But setjmp should fall through. intrinsic llvm.eh.sjlj.setjmp should not have flag isBarrier.
The original case fails at another place after resolving setjmp barrier issue. So I create a new case. And I only focus on PowerPC target, there are some other platforms like ARM, X86 also have same issue.