From patchwork Mon Jun 4 18:34:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 162851 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]) by ozlabs.org (Postfix) with SMTP id 0B4F3B6F9A for ; Tue, 5 Jun 2012 04:34:52 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339439694; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=cOzKfWnth18llyaBAt6fdZ2dci4=; b=r22tfB37/2O9fVI m0aUMBdby3V3Ol7+if0gkQx/+yut2kDXnOulL/cn864GNiZkecC+112OK6t9RGuN vBliahex+XGtSofPmr77498VHJSPCZCMkm5CWFxfA6vhUtDh+cjzvMGaXT80Bo2m 1g8uhLIP7P2xQOnQktUiEa0bd5MA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ijmM/SxOJKHVHIhYJIycT3VYfUAcZY9/pKG7n45TBkDq1OsQwWZ1UFirlMjiaJ 5hQeNF05iilyfiCI7XF0ckZN3NLp+JeYMlQFVL0jVzhkUnltL2u221etWgPJF/eK poa+MUit8j3+BSDwpZ/S8QpYjoH7XHDQBziT2izk5JmbE=; Received: (qmail 30150 invoked by alias); 4 Jun 2012 18:34:41 -0000 Received: (qmail 30059 invoked by uid 22791); 4 Jun 2012 18:34:38 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Jun 2012 18:34:19 +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 (8.14.4/8.14.4) with ESMTP id q54IYJuc005592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Jun 2012 14:34:19 -0400 Received: from ivy.local (ovpn-113-49.phx2.redhat.com [10.3.113.49]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q54IYIjC016604; Mon, 4 Jun 2012 14:34:18 -0400 Message-ID: <4FCCFFAA.80406@redhat.com> Date: Mon, 04 Jun 2012 14:34:18 -0400 From: Vladimir Makarov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: GCC Patches CC: Klaus Pedersen , rdsandiford@googlemail.com Subject: patch to fix reported worsening allocno class choice on the 2nd pass of ira reg costs on MIPS References: <87txz0gm0u.fsf@talisman.home> <4FC40268.5030004@redhat.com> <87wr3oe1d0.fsf@talisman.home> In-Reply-To: <87wr3oe1d0.fsf@talisman.home> X-IsSubscribed: yes 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 The following patch solves the problem. Instead of pressure classes which are focused on relation register moves with memory costs, we use an uniform classes whose register move costs are the same for all their sublcasses. The unifrom classes is used not to slow down the 2nd pass. The patch does not changed the generated code on x86/x86-64 and does not slow IRA down (I've tried it on variety of tests) while it does solve the reported problem. The patch also adds priniting debug info about uniform and important classes. The patch was successfully bootstrapped on x86/x86-64. Committed as rev. 188199. 2012-06-04 Vladimir Makarov * ira-int.h (struct target_ira_int): Add member x_ira_uniform_class_p. (ira_uniform_class_p): New macro. * ira.c (setup_uniform_class_p): New function. (setup_allocno_and_important_classes): Call the function. (print_unform_and_important_classes): New function. (print_classes): Rename to print_translated_classes. (ira_debug_allocno_classes): Add call of print_unform_and_important_classes. * ira-costs.c (setup_regno_cost_classes_by_aclass): Use uniform classes instead of pressure classes. Index: ira.c =================================================================== --- ira.c (revision 188124) +++ ira.c (working copy) @@ -903,6 +903,45 @@ setup_pressure_classes (void) setup_stack_reg_pressure_class (); } +/* Set up IRA_UNIFORM_CLASS_P. Uniform class is a register class + whose register move cost between any registers of the class is the + same as for all its subclasses. We use the data to speed up the + 2nd pass of calculations of allocno costs. */ +static void +setup_uniform_class_p (void) +{ + int i, cl, cl2, m; + + for (cl = 0; cl < N_REG_CLASSES; cl++) + { + ira_uniform_class_p[cl] = false; + if (ira_class_hard_regs_num[cl] == 0) + continue; + /* We can not use alloc_reg_class_subclasses here because move + cost hooks does not take into account that some registers are + unavailable for the subtarget. E.g. for i686, INT_SSE_REGS + is element of alloc_reg_class_subclasses for GENERAL_REGS + because SSE regs are unavailable. */ + for (i = 0; (cl2 = reg_class_subclasses[cl][i]) != LIM_REG_CLASSES; i++) + { + if (ira_class_hard_regs_num[cl2] == 0) + continue; + for (m = 0; m < NUM_MACHINE_MODES; m++) + if (contains_reg_of_mode[cl][m] && contains_reg_of_mode[cl2][m]) + { + ira_init_register_move_cost_if_necessary ((enum machine_mode) m); + if (ira_register_move_cost[m][cl][cl] + != ira_register_move_cost[m][cl2][cl2]) + break; + } + if (m < NUM_MACHINE_MODES) + break; + } + if (cl2 == LIM_REG_CLASSES) + ira_uniform_class_p[cl] = true; + } +} + /* Set up IRA_ALLOCNO_CLASSES, IRA_ALLOCNO_CLASSES_NUM, IRA_IMPORTANT_CLASSES, and IRA_IMPORTANT_CLASSES_NUM. @@ -1008,6 +1047,7 @@ setup_allocno_and_important_classes (voi for (j = 0; j < ira_allocno_classes_num; j++) ira_reg_allocno_class_p[ira_allocno_classes[j]] = true; setup_pressure_classes (); + setup_uniform_class_p (); } /* Setup translation in CLASS_TRANSLATE of all classes into a class @@ -1292,10 +1332,27 @@ setup_reg_class_relations (void) } } -/* Output all possible allocno classes and the translation map into - file F. */ +/* Output all unifrom and important classes into file F. */ +static void +print_unform_and_important_classes (FILE *f) +{ + static const char *const reg_class_names[] = REG_CLASS_NAMES; + int i, cl; + + fprintf (f, "Uniform classes:\n"); + for (cl = 0; cl < N_REG_CLASSES; cl++) + if (ira_uniform_class_p[cl]) + fprintf (f, " %s", reg_class_names[cl]); + fprintf (f, "\nImportant classes:\n"); + for (i = 0; i < ira_important_classes_num; i++) + fprintf (f, " %s", reg_class_names[ira_important_classes[i]]); + fprintf (f, "\n"); +} + +/* Output all possible allocno or pressure classes and their + translation map into file F. */ static void -print_classes (FILE *f, bool pressure_p) +print_translated_classes (FILE *f, bool pressure_p) { int classes_num = (pressure_p ? ira_pressure_classes_num : ira_allocno_classes_num); @@ -1321,8 +1378,9 @@ print_classes (FILE *f, bool pressure_p) void ira_debug_allocno_classes (void) { - print_classes (stderr, false); - print_classes (stderr, true); + print_unform_and_important_classes (stderr); + print_translated_classes (stderr, false); + print_translated_classes (stderr, true); } /* Set up different arrays concerning class subsets, allocno and Index: ira-costs.c =================================================================== --- ira-costs.c (revision 188124) +++ ira-costs.c (working copy) @@ -239,33 +239,19 @@ setup_regno_cost_classes_by_aclass (int COPY_HARD_REG_SET (temp, reg_class_contents[aclass]); AND_COMPL_HARD_REG_SET (temp, ira_no_alloc_regs); /* We exclude classes from consideration which are subsets of - ACLASS only if ACLASS is a pressure class or subset of a - pressure class. It means by the definition of pressure classes - that cost of moving between susbets of ACLASS is cheaper than - load or store. */ - for (i = 0; i < ira_pressure_classes_num; i++) - { - cl = ira_pressure_classes[i]; - if (cl == aclass) - break; - COPY_HARD_REG_SET (temp2, reg_class_contents[cl]); - AND_COMPL_HARD_REG_SET (temp2, ira_no_alloc_regs); - if (hard_reg_set_subset_p (temp, temp2)) - break; - } - exclude_p = i < ira_pressure_classes_num; + ACLASS only if ACLASS is an uniform class. */ + exclude_p = ira_uniform_class_p[aclass]; classes.num = 0; for (i = 0; i < ira_important_classes_num; i++) { cl = ira_important_classes[i]; if (exclude_p) { - /* Exclude no-pressure classes which are subsets of + /* Exclude non-uniform classes which are subsets of ACLASS. */ COPY_HARD_REG_SET (temp2, reg_class_contents[cl]); AND_COMPL_HARD_REG_SET (temp2, ira_no_alloc_regs); - if (! ira_reg_pressure_class_p[cl] - && hard_reg_set_subset_p (temp2, temp) && cl != aclass) + if (hard_reg_set_subset_p (temp2, temp) && cl != aclass) continue; } classes.classes[classes.num++] = cl; Index: ira-int.h =================================================================== --- ira-int.h (revision 188124) +++ ira-int.h (working copy) @@ -828,6 +828,9 @@ struct target_ira_int { classes. */ int x_ira_important_class_nums[N_REG_CLASSES]; + /* Map class->true if class is an uniform class, false otherwise. */ + bool x_ira_uniform_class_p[N_REG_CLASSES]; + /* The biggest important class inside of intersection of the two classes (that is calculated taking only hard registers available for allocation into account;. If the both classes contain no hard @@ -905,6 +908,8 @@ extern struct target_ira_int *this_targe (this_target_ira_int->x_ira_important_classes) #define ira_important_class_nums \ (this_target_ira_int->x_ira_important_class_nums) +#define ira_uniform_class_p \ + (this_target_ira_int->x_ira_uniform_class_p) #define ira_reg_class_intersect \ (this_target_ira_int->x_ira_reg_class_intersect) #define ira_reg_classes_intersect_p \