From patchwork Thu Apr 9 19:43:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 459808 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AA89B140157 for ; Fri, 10 Apr 2015 05:43:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=EVdXOJ4d; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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=hh0MOKug+d/EiUQYdHnqMO6+jkyc8l/D15ad+t7BSrha/K lXvXDPxuFFHkymJ4qL4NIx2kqJwdRTLy3u2m9otwFohWAcWc/U0Fe9jyI0NmaZzq KNYdUTem5VR0OU97wx4/IUZnhGTwp/MH0bBDHjCk6L3E9Gilg18hyS8NQNeo0= 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=FebqPo3Lh6ncYFVbGIdtJPldLY0=; b=EVdXOJ4dKS3kaK37lBHG qTJJ1P94eglDerb7yo12uU1zwhh5RdRjYpQjci8HiRBjODDsNUFfc+7OCpYyQRDH Exw+vxfia3ObKDBksXUiZgGBml9oGBftPIG8orZ1KY1FMw+pf2SUWvFm3rsLvarT CMCnDOMbQO90yLDdT0hLfe0= Received: (qmail 66974 invoked by alias); 9 Apr 2015 19:43:31 -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 66962 invoked by uid 89); 9 Apr 2015 19:43:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 09 Apr 2015 19:43:29 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 1FA3CAB118 for ; Thu, 9 Apr 2015 19:43:28 +0000 (UTC) Received: from topor.usersys.redhat.com (unused-10-15-17-214.yyz.redhat.com [10.15.17.214]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t39JhRmW015183 for ; Thu, 9 Apr 2015 15:43:27 -0400 Message-ID: <5526D65E.6080300@redhat.com> Date: Thu, 09 Apr 2015 15:43:26 -0400 From: Vladimir Makarov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: gcc-patches Subject: patch to fix PR65710 X-IsSubscribed: yes The following patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65710 The patch was bootstrapped and tested on x86/x86-64, ppc64, and aarch64. The patch does not contain the test as it is too big. If it is reduced, the test can be committed. Committed as rev. 221956. I am also submitting analogous patch to gcc-4.9 branch. 2015-04-09 Vladimir Makarov PR target/65710 * lra-int.h (lra_bad_spill_regno_start): New. * lra.c (lra_bad_spill_regno_start): New. (lra): Set up lra_bad_spill_regno_start. Set up lra_constraint_new_regno_start unconditionally. * lra-assigns.c (spill_for): Use lra_bad_spill_regno_start for spill preferences. Index: lra-assigns.c =================================================================== --- lra-assigns.c (revision 221949) +++ lra-assigns.c (working copy) @@ -910,6 +910,7 @@ spill_for (int regno, bitmap spilled_pse enum reg_class rclass; unsigned int spill_regno, reload_regno, uid; int insn_pseudos_num, best_insn_pseudos_num; + int bad_spills_num, smallest_bad_spills_num; lra_live_range_t r; bitmap_iterator bi; @@ -928,6 +929,7 @@ spill_for (int regno, bitmap spilled_pse best_hard_regno = -1; best_cost = INT_MAX; best_insn_pseudos_num = INT_MAX; + smallest_bad_spills_num = INT_MAX; rclass_size = ira_class_hard_regs_num[rclass]; mode = PSEUDO_REGNO_MODE (regno); /* Invalidate try_hard_reg_pseudos elements. */ @@ -958,6 +960,7 @@ spill_for (int regno, bitmap spilled_pse && ! bitmap_bit_p (&lra_optional_reload_pseudos, spill_regno))) goto fail; insn_pseudos_num = 0; + bad_spills_num = 0; if (lra_dump_file != NULL) fprintf (lra_dump_file, " Trying %d:", hard_regno); sparseset_clear (live_range_reload_inheritance_pseudos); @@ -965,6 +968,8 @@ spill_for (int regno, bitmap spilled_pse { if (bitmap_bit_p (&insn_conflict_pseudos, spill_regno)) insn_pseudos_num++; + if (spill_regno >= (unsigned int) lra_bad_spill_regno_start) + bad_spills_num++; for (r = lra_reg_info[spill_regno].live_ranges; r != NULL; r = r->next) @@ -1035,7 +1040,9 @@ spill_for (int regno, bitmap spilled_pse } if (best_insn_pseudos_num > insn_pseudos_num || (best_insn_pseudos_num == insn_pseudos_num - && best_cost > cost)) + && (bad_spills_num < smallest_bad_spills_num + || (bad_spills_num == smallest_bad_spills_num + && best_cost > cost)))) { best_insn_pseudos_num = insn_pseudos_num; best_cost = cost; Index: lra.c =================================================================== --- lra.c (revision 221949) +++ lra.c (working copy) @@ -2180,6 +2180,10 @@ int lra_new_regno_start; /* Start of reload pseudo regnos before the new spill pass. */ int lra_constraint_new_regno_start; +/* Avoid spilling pseudos with regno more than the following value if + it is possible. */ +int lra_bad_spill_regno_start; + /* Inheritance pseudo regnos before the new spill pass. */ bitmap_head lra_inheritance_pseudos; @@ -2269,6 +2273,7 @@ lra (FILE *f) permit changing reg classes for pseudos created by this simplification. */ lra_constraint_new_regno_start = lra_new_regno_start = max_reg_num (); + lra_bad_spill_regno_start = INT_MAX; remove_scratches (); scratch_p = lra_constraint_new_regno_start != max_reg_num (); @@ -2406,12 +2411,14 @@ lra (FILE *f) /* Assignment of stack slots changes elimination offsets for some eliminations. So update the offsets here. */ lra_eliminate (false, false); - /* After switching off inheritance and rematerialization passes, - don't forget reload pseudos after spilling sub-pass to avoid - LRA cycling in some complicated cases. */ - if (lra_inheritance_iter <= LRA_MAX_INHERITANCE_PASSES - || lra_rematerialization_iter <= LRA_MAX_REMATERIALIZATION_PASSES) - lra_constraint_new_regno_start = max_reg_num (); + lra_constraint_new_regno_start = max_reg_num (); + if (lra_bad_spill_regno_start == INT_MAX + && lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES + && lra_rematerialization_iter > LRA_MAX_REMATERIALIZATION_PASSES) + /* After switching off inheritance and rematerialization + passes, avoid spilling reload pseudos will be created to + prevent LRA cycling in some complicated cases. */ + lra_bad_spill_regno_start = lra_constraint_new_regno_start; lra_assignment_iter_after_spill = 0; } restore_scratches (); Index: lra-int.h =================================================================== --- lra-int.h (revision 221949) +++ lra-int.h (working copy) @@ -333,6 +333,7 @@ extern void lra_register_new_scratch_op extern int lra_new_regno_start; extern int lra_constraint_new_regno_start; +extern int lra_bad_spill_regno_start; extern bitmap_head lra_inheritance_pseudos; extern bitmap_head lra_split_regs; extern bitmap_head lra_subreg_reload_pseudos;