From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26702 invoked by alias); 24 Aug 2012 18:17:42 -0000 Received: (qmail 26689 invoked by uid 22791); 24 Aug 2012 18:17:40 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_SR,TW_SV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Aug 2012 18:17:27 +0000 From: "chaoyingfu at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/54369] New: Delayed-branch pass in reorg.c removes too many instructions Date: Fri, 24 Aug 2012 18:17:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chaoyingfu at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg01688.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: chaoyingfu@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!