http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54369
Bug #: 54369 Summary: Delayed-branch pass in reorg.c removes too many instructions Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: chaoyin...@gcc.gnu.org Created attachment 28079 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28079 A simple test for an issue in reorg.c Please check this example when using GCC 4.6 for mips-linux-gnu. (I think the issue is in GCC 4.7 and later as well. But due to the basic block ordering, I cannot reproduce this issue.) Ex: # /gcc46branch/build-mips/gcc/cc1plus -quiet Bug.i -o Bug.s -mips32r2 -O2 # cat Bug.s _Z3bugP9ValueRTRK: .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .set nomacro lw $2,0($4) <--------- lw $2,0($2) <--------- (NO RETURN IN THIS FUNCTION.) .set macro .set reorder .end _Z3bugP9ValueRTRK .cfi_endproc $LFE13: .size _Z3bugP9ValueRTRK, .-_Z3bugP9ValueRTRK .ident "GCC: (GNU) 4.6.4 20120823 (prerelease) [gcc-4_6-branch revision 190613]" The delayed-branch pass in reorg.c is too aggressive, such that a return instruction and others are removed. From debugging code in reorg.c: delete_jump() -> delete_computation() -> delete_related_insn(), I think we should not use delete_related_insn() that removes branches and all the following instructions. A simple fix may be just using delete_insn() in delete_computation(). Ex: # svn diff reorg.c Index: reorg.c =================================================================== --- reorg.c (revision 190636) +++ reorg.c (working copy) @@ -3298,7 +3298,7 @@ delete_prior_computation (note, insn); } - delete_related_insns (insn); + delete_insn (insn); } /* If all INSN does is set the pc, delete it, Ex: (Bug.s after this fix.) # cat Bug.s _Z3bugP9ValueRTRK: .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .set nomacro lw $2,0($4) lw $2,0($2) $L4: j $31 <------------- OK srl $2,$2,8 <------------- OK .set macro .set reorder .end _Z3bugP9ValueRTRK .cfi_endproc $LFE13: .size _Z3bugP9ValueRTRK, .-_Z3bugP9ValueRTRK .ident "GCC: (GNU) 4.6.4 20120823 (prerelease) [gcc-4_6-branch revision 190613]" Thanks!