unreachable branch in codegen for switch statement
Venkatachalam, Vasanth
Vasanth.Venkatachalam at amd.com
Tue Nov 5 18:22:08 PST 2013
Doug or others-
When I ran the test case below through the AMD64 backend, I noticed an unreachable branch in the code generated below. Namely, the jmp instruction at 0x00007facc8145a60. It appears this is coming from the call to emitJump( ) in LIRGenerator.doBlock( ), which appends a jump instruction to the end of each basic block, which may later get optimized away by the reg. allocator. Is there a reason why this jmp isn't being optimized away? Is there any way around this?
I tried -G:+RemoveNeverExecutedCode but this isn't making a difference.
I'm hitting the same issue when I generate HSAIL code for this switch statement, but I get an assembler error due to this unreachable branch.
public int switchTest(int n) {
switch (n) {
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
default:
return 3;
}
}
0x00007facc8145a40: cmp edx,0x0
0x00007facc8145a43: je 0x00007facc8145a6b
0x00007facc8145a49: cmp edx,0x1
0x00007facc8145a4c: je 0x00007facc8145a72
0x00007facc8145a52: cmp edx,0x2
0x00007facc8145a55: je 0x00007facc8145a79
0x00007facc8145a5b: jmp 0x00007facc8145a65
0x00007facc8145a60: jmp 0x00007facc8145a6b //unreachable code
0x00007facc8145a65: mov eax,0x3
0x00007facc8145a6a: ret
0x00007facc8145a6b: mov eax,0x0 //case 0
0x00007facc8145a70: jmp 0x00007facc8145a6a
0x00007facc8145a72: mov eax,0x1 //case 1
0x00007facc8145a77: jmp 0x00007facc8145a6a
0x00007facc8145a79: mov eax,0x2 //case 2
0x00007facc8145a7e: jmp 0x00007facc8145a6a
More information about the graal-dev
mailing list