From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14928 invoked by alias); 9 Dec 2014 08:48:42 -0000 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 Received: (qmail 14853 invoked by uid 48); 9 Dec 2014 08:48:38 -0000 From: "amker.cheng at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/62151] [5 Regression] wrong code at -O2 and -O3 on x86_64-linux-gnu Date: Tue, 09 Dec 2014 08:48:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: amker.cheng at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 5.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-12/txt/msg00848.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62151 bin.cheng changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amker.cheng at gmail dot com, | |law at redhat dot com --- Comment #12 from bin.cheng --- Seems there are two problems in distribute_notes when handling REG_DEAD note. Quote from source code: if (from_insn && CALL_P (from_insn) && find_reg_fusage (from_insn, USE, XEXP (note, 0))) place = from_insn; else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3))) place = i3; else if (i2 != 0 && next_nonnote_nondebug_insn (i2) == i3 && reg_referenced_p (XEXP (note, 0), PATTERN (i2))) place = i2; else if ((rtx_equal_p (XEXP (note, 0), elim_i2) && !(i2mod && reg_overlap_mentioned_p (XEXP (note, 0), i2mod_old_rhs))) || rtx_equal_p (XEXP (note, 0), elim_i1) || rtx_equal_p (XEXP (note, 0), elim_i0)) break; tem_insn = i3; Issue 1, Checks against elim_i0/elim_i1/elim_i2 and their values are not correct for some cases. In this case as below i0: r0 <- i0src i1: r1 <- i1src (using r0) REG_DEAD (r0) i2: r0 <- i2src (using r1) i3: r3 <- i3src (using r0) ix: other use of r0 In try_combine, elim_i0/elim_i1/elim_i2 are set to 0/r1/0 correspondingly. When calling distribute_notes for reg_notes in i1, the check "rtx_equal_p (XEXP (note, 0), elim_i0)" evaluates to FALSE. As a result, GCC falls through to below code which is to handle another note distribution case. This is why I thought the logic doesn't make any sense at the first glance. So If variables elim_i0/elim_i1/elim_i2 are set to correct values, distribution_notes acts as expected by discarding the REG_DEAD note. The point is, when we distributing REG_DEAD note in i1, elim_i0 should be set to i1dest (r0 in the example), which means r0 is eliminated as far as i1 is handled, no matter if it is re-set by i2 or not. Another issue is about tem_insn, I think in any cases, we should start searching reference/def of the noted register from "from_insn" (if it exist). Think about below case: ix: rA <- xxx i0: r0 <- const_0 i1: r1 <- rA & r0 REG_DEAD (rA) i2: r0 <- i2src (using r1) iy: rA <- yyy i3: r3 <- i3src (using r0) Starting from i3, we will delete insn iy, but what should be deleted actually is insn ix!