SelectionDAGBuilder::visitSwitch() creates disconnected MBB
| 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
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.
Should be fixed by r266479.
Reduced some more:
; ModuleID = '
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 }
repro for feeding to llc Thanks for the bug report!
Shorter repro invocation:
$ llc -verify-machineinstrs < a.ll