From patchwork Fri May 30 09:20:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 354000 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 D0E23140099 for ; Fri, 30 May 2014 19:20:56 +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:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=CZYnGjC9RukcOr5Wy RT273AmXsmG7EVS02xPRjMutWh+iQTBHWHHOC+N8qFqExDoeWPgU3T2evfifK10J Xm52l0G9ozV6bmeOKA6ZjSIn2+Hl7kmB9/3555A2IsBLIh8ObOgLHgaGTvijXiZd EPDR9M+NSrHwr3PqTdTNiQhyw8= 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:cc:subject:references :in-reply-to:content-type; s=default; bh=mzRARAABn7zAtEgXN8YxBau fe44=; b=QcYy9wdN/YEC4siObzOnqNa1aWu+xsgWipjyWFQOWIkNtj+dbrwDc4u 2H/vvYSCJ62GykS+JKZ9nsin9hU9VAsDsZnZepNlmZnQvTg+vJgo5yLPP+AnSOZo KQXtun8t8GzzaiCLIArERtoJiMZ4klc75LxSgNqYZljEzDJQsPO4= Received: (qmail 1293 invoked by alias); 30 May 2014 09:20:44 -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 1188 invoked by uid 89); 30 May 2014 09:20:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 May 2014 09:20:41 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WqIzM-0002Tg-Qf from Tom_deVries@mentor.com ; Fri, 30 May 2014 02:20:36 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 30 May 2014 02:20:36 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Fri, 30 May 2014 10:20:34 +0100 Message-ID: <53884D61.3000402@mentor.com> Date: Fri, 30 May 2014 11:20:33 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Vladimir Makarov CC: Subject: Re: [PATCH][IRA] Analysis of register usage of functions for usage by IRA. References: <510282FE.1060809@mentor.com> <5102A694.5010000@redhat.com> <5113FC6B.7090702@mentor.com> <511C1538.308@redhat.com> <514199BC.9070608@mentor.com> <52A11E8E.8090103@mentor.com> <52D591AA.4060103@redhat.com> In-Reply-To: <52D591AA.4060103@redhat.com> On 14-01-14 20:36, Vladimir Makarov wrote: >>> Unfortunately I haven't been able to find time to work further on the >>> >>LRA part. >>> >>So if you're still willing to pick up that part, that would be great. >> > >> >Vladimir, >> > >> >I gave this a try. The attached patch works for the included test-case >> >for x86_64. >> > >> >I've bootstrapped and reg-tested the patch (in combination with the >> >other patches from the series) on x86_64. >> > >> >OK for stage1? >> > > Yes, it is ok for stage1. Thanks for not forgetting LRA and sorry for > the delay with the answer (it is not a high priority patch for me right > now). > > I believe, this patch helps to improve code also because of better > spilling into SSE regs. Spilling into SSE regs instead of memory has a > rare probability right now as all SSE regs are call clobbered. > Vladimir, After committing the original patch, Martin Liška told me on IRC that the patch broke the build with --enable-checking=release. The bit in lra_assign used the call_p field unconditionally, while the definition of the call_p field is guarded with #ifdef ENABLE_CHECKING. I've reverted the original patch, and bootstrapped and reg-tested this version of the patch, which has a simplified bit for lra_assign. The only functional difference between the patches is that we no longer add printing a debug message in lra_assign. Committed (since the difference between the approved and new patch is trivial). Thanks, - Tom 2014-05-30 Tom de Vries * lra-int.h (struct lra_reg): Add field actual_call_used_reg_set. * lra.c (initialize_lra_reg_info_element): Add init of actual_call_used_reg_set field. (lra): Call lra_create_live_ranges before lra_inheritance for -fuse-caller-save. * lra-assigns.c (lra_assign): Allow call_used_regs to cross calls for -fuse-caller-save. * lra-constraints.c (need_for_call_save_p): Use actual_call_used_reg_set instead of call_used_reg_set for -fuse-caller-save. * lra-lives.c (process_bb_lives): Calculate actual_call_used_reg_set. diff --git a/gcc/lra-assigns.c b/gcc/lra-assigns.c index f7bb86b..03c2506 100644 --- a/gcc/lra-assigns.c +++ b/gcc/lra-assigns.c @@ -1460,12 +1460,13 @@ lra_assign (void) create_live_range_start_chains (); setup_live_pseudos_and_spill_after_risky_transforms (&all_spilled_pseudos); #ifdef ENABLE_CHECKING - for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) - if (lra_reg_info[i].nrefs != 0 && reg_renumber[i] >= 0 - && lra_reg_info[i].call_p - && overlaps_hard_reg_set_p (call_used_reg_set, - PSEUDO_REGNO_MODE (i), reg_renumber[i])) - gcc_unreachable (); + if (!flag_use_caller_save) + for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) + if (lra_reg_info[i].nrefs != 0 && reg_renumber[i] >= 0 + && lra_reg_info[i].call_p + && overlaps_hard_reg_set_p (call_used_reg_set, + PSEUDO_REGNO_MODE (i), reg_renumber[i])) + gcc_unreachable (); #endif /* Setup insns to process on the next constraint pass. */ bitmap_initialize (&changed_pseudo_bitmap, ®_obstack); diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c index 2df841a..7eb9dbc 100644 --- a/gcc/lra-constraints.c +++ b/gcc/lra-constraints.c @@ -4605,7 +4605,10 @@ need_for_call_save_p (int regno) lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0); return (usage_insns[regno].calls_num < calls_num && (overlaps_hard_reg_set_p - (call_used_reg_set, + ((flag_use_caller_save && + ! hard_reg_set_empty_p (lra_reg_info[regno].actual_call_used_reg_set)) + ? lra_reg_info[regno].actual_call_used_reg_set + : call_used_reg_set, PSEUDO_REGNO_MODE (regno), reg_renumber[regno]) || HARD_REGNO_CALL_PART_CLOBBERED (reg_renumber[regno], PSEUDO_REGNO_MODE (regno)))); diff --git a/gcc/lra-int.h b/gcc/lra-int.h index 41c9849..3c89734 100644 --- a/gcc/lra-int.h +++ b/gcc/lra-int.h @@ -77,6 +77,10 @@ struct lra_reg /* The following fields are defined only for pseudos. */ /* Hard registers with which the pseudo conflicts. */ HARD_REG_SET conflict_hard_regs; + /* Call used registers with which the pseudo conflicts, taking into account + the registers used by functions called from calls which cross the + pseudo. */ + HARD_REG_SET actual_call_used_reg_set; /* We assign hard registers to reload pseudos which can occur in few places. So two hard register preferences are enough for them. The following fields define the preferred hard registers. If diff --git a/gcc/lra-lives.c b/gcc/lra-lives.c index 8444ade..26ba0d2 100644 --- a/gcc/lra-lives.c +++ b/gcc/lra-lives.c @@ -624,6 +624,17 @@ process_bb_lives (basic_block bb, int &curr_point) if (call_p) { + if (flag_use_caller_save) + { + HARD_REG_SET this_call_used_reg_set; + get_call_reg_set_usage (curr_insn, &this_call_used_reg_set, + call_used_reg_set); + + EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j) + IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set, + this_call_used_reg_set); + } + sparseset_ior (pseudos_live_through_calls, pseudos_live_through_calls, pseudos_live); if (cfun->has_nonlocal_label diff --git a/gcc/lra.c b/gcc/lra.c index ecec890..d199a81 100644 --- a/gcc/lra.c +++ b/gcc/lra.c @@ -1427,6 +1427,7 @@ initialize_lra_reg_info_element (int i) lra_reg_info[i].no_stack_p = false; #endif CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs); + CLEAR_HARD_REG_SET (lra_reg_info[i].actual_call_used_reg_set); lra_reg_info[i].preferred_hard_regno1 = -1; lra_reg_info[i].preferred_hard_regno2 = -1; lra_reg_info[i].preferred_hard_regno_profit1 = 0; @@ -2344,7 +2345,18 @@ lra (FILE *f) lra_eliminate (false, false); /* Do inheritance only for regular algorithms. */ if (! lra_simple_p) - lra_inheritance (); + { + if (flag_use_caller_save) + { + 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); + } + lra_inheritance (); + } if (live_p) lra_clear_live_ranges (); /* We need live ranges for lra_assign -- so build them. */ -- 1.9.1