llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

SelectionDAGBuilder::visitSwitch() creates disconnected MBB

Open JonPsson opened this issue 10 years ago • 3 comments

Bugzilla Link 27135
Resolution FIXED
Resolved on Apr 15, 2016 16:49
Version trunk
OS Linux
Attachments Input for compilation
CC @zmodem

Extended Description

visitSwitch() seems to create an MBB whithout predecessors / successors.

The attached test case is not minimized, but the verifier gives the exact spot. If you are lucky, you can get there in gdb with:

b MachineFunction:247 // in CreateMachineBasicBlock()

condition [BP] (bb && strcmp(bb->getName().Data,"if.then72")==0) c // continue once

u // go up the stack a few times, and that should be the SelectionDAGBuilder handling bb:

if.then72: ; preds = %land.lhs.true71 %24 = inttoptr i64 %in.addr.sroa.0.0 to %struct.rtx_def* %arrayidx74 = getelementptr inbounds %struct.rtx_def, %struct.rtx_def* %24, i64 0, i32 1, i64 0 %25 = bitcast %union.rtunion_def* %arrayidx74 to i32** %26 = load i32*, i32** %25, align 8, !tbaa !​5 %bf.load75 = load i32, i32* %26, align 8 %bf.lshr76 = lshr i32 %bf.load75, 16 switch i32 %bf.lshr76, label %if.end92 [ i32 99, label %sw.bb i32 98, label %sw.bb i32 101, label %sw.bb i32 97, label %sw.bb84 i32 96, label %sw.bb84 i32 100, label %sw.bb84 ]

(gdb) run -cc1 -triple s390x-ibm-linux -S -disable-free -main-file-name reload.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu z13 -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -O3 -ferror-limit 19 -fmessage-length 238 -funroll-loops -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o reload.s -x ir ./reload.bc

Add -mllvm -verify-machineinstrs to see the error message:

...

BB#524: derived from LLVM BB %if.then72 Predecessors according to CFG: BB#17 %vreg455 = LHIMux 1; GR32Bit:%vreg455 %vreg456<def,tied1> = SLL %vreg455, %vreg453, 0; GR32Bit:%vreg456,%vreg455 ADDR32Bit:%vreg453 TMLMux %vreg456, 19, %CC; GR32Bit:%vreg456 BRC 15, 7, <BB#19>, %CC J <BB#18> Successors according to CFG: BB#19(0x40000000 / 0x80000000 = 50.00%) BB#18(0x40000000 / 0x80000000 = 50.00%)

BB#525: derived from LLVM BB %if.then72 <<<<<<<<< Not connected!!

BB#18: derived from LLVM BB %sw.bb ...

*** Bad machine code: PHI operand is not in the CFG ***

  • function: push_reload
  • basic block: BB#20 if.end92 (0x85a2f140)
  • instruction: %vreg17 = PHI
  • operand 16: <BB#525>

*** Bad machine code: PHI operand is not in the CFG ***

  • function: push_reload
  • basic block: BB#20 if.end92 (0x85a2f140)
  • instruction: %vreg18 = PHI
  • operand 16: <BB#525> fatal error: error in backend: Found 2 machine code errors.

JonPsson avatar Mar 30 '16 20:03 JonPsson

Should be fixed by r266479.

zmodem avatar Apr 15 '16 23:04 zmodem

Reduced some more:

; ModuleID = '' source_filename = "bugpoint-output-d4b46c1.bc" target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" target triple = "s390x-ibm-linux"

declare i32 @​foo(i32)

define void @​push_reload(i32 %type) { entry: br i1 undef, label %sw, label %end

sw: switch i32 %type, label %end [ i32 99, label %sw.bb i32 98, label %sw.bb i32 101, label %sw.bb i32 97, label %sw.bb2 i32 96, label %sw.bb2 i32 100, label %sw.bb2 ]

sw.bb: unreachable

sw.bb2: unreachable

end: %p = phi i32 [ 1, %sw ], [ 0, %entry ] %c = call i32 @​foo(i32 %p) ret void }

zmodem avatar Apr 15 '16 19:04 zmodem

repro for feeding to llc Thanks for the bug report!

Shorter repro invocation:

$ llc -verify-machineinstrs < a.ll

zmodem avatar Mar 31 '16 01:03 zmodem