From patchwork Tue Sep 10 15:39:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 273918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 86B952C00E7 for ; Wed, 11 Sep 2013 01:40:07 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=CmUOuYjLrAyefi08bUT1iB19oHV2d0CtjEKlSNqEjC4j5a lH4dM7GhHRIvK3zmagqtGJX4P9oJj1cPHcJGK+t3+q9WtvssQHeG+W98FDRcFJxr ltj+ifd4M0MfmC2qXEOmxHqAy/sB+RaPnucHQGpXSUAQRvOaFmU+fwqc87uGQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=JOxAhr2ijdX/TlHR0e5+vAQ3zzA=; b=STeaye/StjCQUMOiCVT/ d9ileOPkkx3pfhFQr129FOia34UnynavdFDzva0p8Jbl5320R5r3lO4HcN5JfoT0 HYAcxR//hpBWUSrx1iGVDhxq0qQGl73UIZyI7JsAAKhIR0pl3QpgoMtoT6YfWiRd LBeZHB5n6WP3HWL+qmps5dY= Received: (qmail 29388 invoked by alias); 10 Sep 2013 15:40:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29369 invoked by uid 89); 10 Sep 2013 15:40:00 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Sep 2013 15:40:00 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8AFdg2V021359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 10 Sep 2013 11:39:42 -0400 Received: from topor.usersys.redhat.com ([10.15.16.142]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r8AFdf6Y008302 for ; Tue, 10 Sep 2013 11:39:42 -0400 Message-ID: <522F3D3D.4000701@redhat.com> Date: Tue, 10 Sep 2013 11:39:41 -0400 From: Vladimir Makarov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: gcc-patches Subject: patch implementing a new version of optional reloads X-IsSubscribed: yes The following patch switches on optional reloads. The optional reload patch resolves PR55342. The original code was switched off as it resulted in new GCC failures. The current code contains a new version of optional reload implementation. I've tried many different strategies to use optional reloads, all of them (except twos) resulted in SPEC2000 performance degradation. The current heuristic is the best and probably one of the simplest one. It results in about 0.6% and 0.7% SPECFP2000 performance improvement for x86-64 and x86 (measured on i5-4670 with using -O3 -mtune=corei7). That is the best what I got on SPEC2000. The biggest average size increase is about 0.2% for SPECFP2000 on x86 and less 0.07% for SPECInt2000 on x86/x86-64 (for x86-64 SPECFP2000 the average code size is actually smaller). The patch was successfully bootstrapped an tested on x86/x86-64. Committed as rev. 202468. 2013-09-10 Vladimir Makarov * lra.c (lra): Clear lra_optional_reload_pseudos before every constraint pass. * lra-constraints.c (curr_insn_transform): Switch on optional reloads. Check destination too to check move insn. (undo_optional_reloads): Add check that the original peudo did not changed its allocation and the optional reload was inherited on last inheritance pass. Break loop after deciding to keep optional reload. (lra_undo_inheritance): Add check that inherited pseudo still in memory. Index: lra.c =================================================================== --- lra.c (revision 202223) +++ lra.c (working copy) @@ -2313,6 +2313,7 @@ lra (FILE *f) { for (;;) { + bitmap_clear (&lra_optional_reload_pseudos); /* We should try to assign hard registers to scratches even if there were no RTL transformations in lra_constraints. */ @@ -2363,7 +2364,6 @@ lra (FILE *f) if (! live_p) lra_clear_live_ranges (); } - bitmap_clear (&lra_optional_reload_pseudos); } bitmap_clear (&lra_subreg_reload_pseudos); bitmap_clear (&lra_inheritance_pseudos); Index: lra-constraints.c =================================================================== --- lra-constraints.c (revision 202223) +++ lra-constraints.c (working copy) @@ -3307,15 +3307,19 @@ curr_insn_transform (void) reg, we might improve the code through inheritance. If it does not get a hard register we coalesce memory/memory moves later. Ignore move insns to avoid cycling. */ - if (0 && ! lra_simple_p + if (! lra_simple_p && lra_undo_inheritance_iter < LRA_MAX_INHERITANCE_PASSES && goal_alt[i] != NO_REGS && REG_P (op) && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER + && ! lra_former_scratch_p (regno) && reg_renumber[regno] < 0 && (curr_insn_set == NULL_RTX - || !(REG_P (SET_SRC (curr_insn_set)) - || MEM_P (SET_SRC (curr_insn_set)) - || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG))) + || !((REG_P (SET_SRC (curr_insn_set)) + || MEM_P (SET_SRC (curr_insn_set)) + || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG) + && (REG_P (SET_DEST (curr_insn_set)) + || MEM_P (SET_DEST (curr_insn_set)) + || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG)))) optional_p = true; else continue; @@ -5439,7 +5443,7 @@ remove_inheritance_pseudos (bitmap remov static bool undo_optional_reloads (void) { - bool change_p; + bool change_p, keep_p; unsigned int regno, uid; bitmap_iterator bi, bi2; rtx insn, set, src, dest; @@ -5449,26 +5453,42 @@ undo_optional_reloads (void) bitmap_copy (&removed_optional_reload_pseudos, &lra_optional_reload_pseudos); EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi) if (reg_renumber[regno] >= 0) - EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2) - { - insn = lra_insn_recog_data[uid]->insn; - if ((set = single_set (insn)) == NULL_RTX) - continue; - src = SET_SRC (set); - dest = SET_DEST (set); - if (! REG_P (src) || ! REG_P (dest)) - continue; - if ((REGNO (src) == regno - && lra_reg_info[regno].restore_regno != (int) REGNO (dest)) - || (REGNO (dest) == regno - && lra_reg_info[regno].restore_regno != (int) REGNO (src))) - { - /* Optional reload was inherited. Keep it. */ - bitmap_clear_bit (&removed_optional_reload_pseudos, regno); - if (lra_dump_file != NULL) - fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno); + { + keep_p = false; + if (reg_renumber[lra_reg_info[regno].restore_regno] >= 0) + /* If the original pseudo changed its allocation, just + removing the optional pseudo is dangerous as the original + pseudo will have longer live range. */ + keep_p = true; + else + EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2) + { + insn = lra_insn_recog_data[uid]->insn; + if ((set = single_set (insn)) == NULL_RTX) + continue; + src = SET_SRC (set); + dest = SET_DEST (set); + if (! REG_P (src) || ! REG_P (dest)) + continue; + if (REGNO (dest) == regno + /* Ignore insn for optional reloads itself. */ + && lra_reg_info[regno].restore_regno != (int) REGNO (src) + /* Check only inheritance on last inheritance pass. */ + && (int) REGNO (src) >= new_regno_start + /* Check that the optional reload was inherited. */ + && bitmap_bit_p (&lra_inheritance_pseudos, REGNO (src))) + { + keep_p = true; + break; + } } - } + if (keep_p) + { + bitmap_clear_bit (&removed_optional_reload_pseudos, regno); + if (lra_dump_file != NULL) + fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno); + } + } change_p = ! bitmap_empty_p (&removed_optional_reload_pseudos); bitmap_initialize (&insn_bitmap, ®_obstack); EXECUTE_IF_SET_IN_BITMAP (&removed_optional_reload_pseudos, 0, regno, bi) @@ -5550,7 +5570,11 @@ lra_undo_inheritance (void) if (lra_reg_info[regno].restore_regno >= 0) { n_all_inherit++; - if (reg_renumber[regno] < 0) + if (reg_renumber[regno] < 0 + /* If the original pseudo changed its allocation, just + removing inheritance is dangerous as for changing + allocation we used shorter live-ranges. */ + && reg_renumber[lra_reg_info[regno].restore_regno] < 0) bitmap_set_bit (&remove_pseudos, regno); else n_inherit++;