From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63515 invoked by alias); 21 Jun 2015 13:31:38 -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 63481 invoked by uid 48); 21 Jun 2015 13:31:32 -0000 From: "bernd.edlinger at hotmail dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/66614] LRA might fail to eliminate dead code Date: Sun, 21 Jun 2015 13:31: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: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bernd.edlinger at hotmail dot de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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: 2015-06/txt/msg01849.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66614 --- Comment #2 from Bernd Edlinger --- this is what I understand from lra in my own words: lra () consists of a sequence of for (;;) { ... lra_eliminate (false, false); /* Do inheritance only for regular algorithms. */ if (! lra_simple_p) { if (flag_ipa_ra) { if (live_p) lra_clear_live_ranges (); /* As a side-effect of lra_create_live_ranges, we calculate actual_call_used_reg_set, which is needed during lra_inheritance. */ lra_create_live_ranges (true, true); live_p = true; } lra_inheritance (); } if (live_p) lra_clear_live_ranges (); ... } and it is finally fixated by lra_eliminate (true, false); which actually replaces the base register, but keeps the offsets as they are the RTL transformations are done by lra_eliminate_regs_1 (): first it is called with subst_p=false, update_p=false, full_p=true, this replaces the offset relative to from_rtx to to_rtx, but keeps the previous base register. then it is repeatedly called with subst_p=false, update_p=true, full_p=false, which adds some minor corrections to the offset, and again keeps the to be eliminated base register. finally it is called with subst_p=true, update_p=false, full_p=false, this time only the base register is replaced but the offsets are already relative to the target base register. lra_create_live_ranges calls process_bb_lives repeatedly which uses this as a pre-condition of a dead insn which and can be eliminated: if (dead_insn_p && set != NULL_RTX && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX && ! may_trap_p (PATTERN (curr_insn)) /* Don't do premature remove of pic offset pseudo as we can start to use it after some reload generation. */ && (pic_offset_table_rtx == NULL_RTX || pic_offset_table_rtx != SET_DEST (set))) now may_trap_p sees the offsets which are not consistent with the base.