From patchwork Fri May 8 21:12:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 1286455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=VGXAIIO0; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49JjjR5fGcz9sSG for ; Sat, 9 May 2020 07:13:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 78DE1386F82E; Fri, 8 May 2020 21:13:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78DE1386F82E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588972390; bh=5+lu7paT6Zlz5KeVy+GAJ8cCo9DE1iFmbOm4qsGD65E=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VGXAIIO0Sv6L88Ozyg3M/4C0RO/rjOIIPu50vmJrAMUyDnsd3yC2s4pm2wEx9Ayd/ CFUHAC/zkkusyMxvYVcPul0RJP6tSvX4PUk3Md107cUVsJal+c5VhPbSUlkJwrcFsK S0chulBpY7Y+ppVjKt4xs+AF2SjStzbxFsI1LZB0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id CA75A3851C36 for ; Fri, 8 May 2020 21:13:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CA75A3851C36 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-Y8kahDOfPzGt8qQOYkgqcQ-1; Fri, 08 May 2020 17:13:01 -0400 X-MC-Unique: Y8kahDOfPzGt8qQOYkgqcQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B4115100CCC6 for ; Fri, 8 May 2020 21:13:00 +0000 (UTC) Received: from [10.10.112.111] (ovpn-112-111.rdu2.redhat.com [10.10.112.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CF53100164D for ; Fri, 8 May 2020 21:13:00 +0000 (UTC) Subject: [PATCH]: Improving hard reg preference cost propagation To: "gcc-patches@gcc.gnu.org" Message-ID: <4ad76909-6b3b-2bc1-707a-b4a6483ef330@redhat.com> Date: Fri, 8 May 2020 17:12:59 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-19.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vladimir Makarov via Gcc-patches From: Vladimir Makarov Reply-To: Vladimir Makarov Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The following patch improves hard reg pref cost propagation in IRA.  Hard reg preferences are created mainly from moves involving hard regs in RTL.   The patch does the propagation during coloring now and also updates conflict costs which affects hard reg preferences for conflicting allocnos.   The patch was successfully bootstrapped and benchmarked on x86_64 and tested on several other targets.   The patch results in failure gcc.target/i386/pr92807-1.c.  The test should check that GCC does not generate 'leal (r0,r0),r1' but instead checks any leal.  The patch results in generation of 'leal (%rdi,%rdx), %eax' and 1 insn less than GCC w/o the patch. So I fixed the test too. The patch also generates 1 less insn for test 'gcc.target/i386/pr92807-1.c' but it is still not enough to remove XFAIL for this test. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 21eabf82113..75cc642b5a0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2020-05-08 Vladimir Makarov + + * ira-color.c (update_costs_from_allocno): Remove + conflict_cost_update_p argument. Propagate costs only along + threads. Always do conflict cost update. Add printing debugging + info. + (update_costs_from_copies): Add printing debugging info. + (restore_costs_from_copies): Ditto. + (assign_hard_reg): Improve debug info. + (push_only_colorable): Ditto. Call update_costs_from_prefs. + (color_allocnos): Remove update_costs_from_prefs. + 2020-05-08 Richard Biener * tree-vectorizer.h (vec_info::slp_loads): New. diff --git a/gcc/ira-color.c b/gcc/ira-color.c index 0ffdd192020..dbb3b7a2a51 100644 --- a/gcc/ira-color.c +++ b/gcc/ira-color.c @@ -1356,13 +1356,11 @@ allocnos_conflict_p (ira_allocno_t a1, ira_allocno_t a2) /* Update (decrease if DECR_P) HARD_REGNO cost of allocnos connected by copies to ALLOCNO to increase chances to remove some copies as - the result of subsequent assignment. Update conflict costs only - for true CONFLICT_COST_UPDATE_P. Record cost updates if RECORD_P is - true. */ + the result of subsequent assignment. Update conflict costs. + Record cost updates if RECORD_P is true. */ static void update_costs_from_allocno (ira_allocno_t allocno, int hard_regno, - int divisor, bool decr_p, bool record_p, - bool conflict_cost_update_p) + int divisor, bool decr_p, bool record_p) { int cost, update_cost, update_conflict_cost; machine_mode mode; @@ -1391,7 +1389,9 @@ update_costs_from_allocno (ira_allocno_t allocno, int hard_regno, gcc_unreachable (); if (another_allocno == from - || allocnos_conflict_p (another_allocno, start)) + || (ALLOCNO_COLOR_DATA (another_allocno) != NULL + && (ALLOCNO_COLOR_DATA (allocno)->first_thread_allocno + != ALLOCNO_COLOR_DATA (another_allocno)->first_thread_allocno))) continue; aclass = ALLOCNO_CLASS (another_allocno); @@ -1417,15 +1417,13 @@ update_costs_from_allocno (ira_allocno_t allocno, int hard_regno, cost = -cost; update_cost = cp->freq * cost / divisor; - update_conflict_cost = conflict_cost_update_p ? update_cost : 0; - - if (ALLOCNO_COLOR_DATA (another_allocno) != NULL - && (ALLOCNO_COLOR_DATA (allocno)->first_thread_allocno - != ALLOCNO_COLOR_DATA (another_allocno)->first_thread_allocno)) - /* Decrease conflict cost of ANOTHER_ALLOCNO if it is not - in the same allocation thread. */ - update_conflict_cost /= COST_HOP_DIVISOR; + update_conflict_cost = update_cost; + if (internal_flag_ira_verbose > 5 && ira_dump_file != NULL) + fprintf (ira_dump_file, + " a%dr%d (hr%d): update cost by %d, conflict cost by %d\n", + ALLOCNO_NUM (another_allocno), ALLOCNO_REGNO (another_allocno), + hard_regno, update_cost, update_conflict_cost); if (update_cost == 0) continue; @@ -1453,8 +1451,13 @@ update_costs_from_prefs (ira_allocno_t allocno) start_update_cost (); for (pref = ALLOCNO_PREFS (allocno); pref != NULL; pref = pref->next_pref) - update_costs_from_allocno (allocno, pref->hard_regno, - COST_HOP_DIVISOR, true, true, false); + { + if (internal_flag_ira_verbose > 5 && ira_dump_file != NULL) + fprintf (ira_dump_file, " Start updating from pref of hr%d for a%dr%d:\n", + pref->hard_regno, ALLOCNO_NUM (allocno), ALLOCNO_REGNO (allocno)); + update_costs_from_allocno (allocno, pref->hard_regno, + COST_HOP_DIVISOR, true, true); + } } /* Update (decrease if DECR_P) the cost of allocnos connected to @@ -1469,7 +1472,10 @@ update_costs_from_copies (ira_allocno_t allocno, bool decr_p, bool record_p) hard_regno = ALLOCNO_HARD_REGNO (allocno); ira_assert (hard_regno >= 0 && ALLOCNO_CLASS (allocno) != NO_REGS); start_update_cost (); - update_costs_from_allocno (allocno, hard_regno, 1, decr_p, record_p, true); + if (internal_flag_ira_verbose > 5 && ira_dump_file != NULL) + fprintf (ira_dump_file, " Start updating from a%dr%d by copies:\n", + ALLOCNO_NUM (allocno), ALLOCNO_REGNO (allocno)); + update_costs_from_allocno (allocno, hard_regno, 1, decr_p, record_p); } /* Update conflict_allocno_hard_prefs of allocnos conflicting with @@ -1517,9 +1523,12 @@ restore_costs_from_copies (ira_allocno_t allocno) return; records = ALLOCNO_COLOR_DATA (allocno)->update_cost_records; start_update_cost (); + if (internal_flag_ira_verbose > 5 && ira_dump_file != NULL) + fprintf (ira_dump_file, " Start restoring from a%dr%d:\n", + ALLOCNO_NUM (allocno), ALLOCNO_REGNO (allocno)); for (curr = records; curr != NULL; curr = curr->next) update_costs_from_allocno (allocno, curr->hard_regno, - curr->divisor, true, false, true); + curr->divisor, true, false); free_update_cost_record_list (records); ALLOCNO_COLOR_DATA (allocno)->update_cost_records = NULL; } @@ -1934,6 +1943,8 @@ assign_hard_reg (ira_allocno_t a, bool retry_p) if (internal_flag_ira_verbose > 5 && ira_dump_file != NULL) fprintf (ira_dump_file, "(%d=%d,%d) ", hard_regno, cost, full_cost); } + if (internal_flag_ira_verbose > 5 && ira_dump_file != NULL) + fprintf (ira_dump_file, "\n"); if (min_full_cost > mem_cost /* Do not spill static chain pointer pseudo when non-local goto is used. */ @@ -2112,7 +2123,7 @@ form_threads_from_copies (int cp_num) if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL) fprintf (ira_dump_file, - " Forming thread by copy %d:a%dr%d-a%dr%d (freq=%d):\n", + " Forming thread by copy %d:a%dr%d-a%dr%d (freq=%d):\n", cp->num, ALLOCNO_NUM (cp->first), ALLOCNO_REGNO (cp->first), ALLOCNO_NUM (cp->second), ALLOCNO_REGNO (cp->second), cp->freq); @@ -2120,7 +2131,7 @@ form_threads_from_copies (int cp_num) if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL) { thread1 = ALLOCNO_COLOR_DATA (thread1)->first_thread_allocno; - fprintf (ira_dump_file, " Result (freq=%d): a%dr%d(%d)", + fprintf (ira_dump_file, " Result (freq=%d): a%dr%d(%d)", ALLOCNO_COLOR_DATA (thread1)->thread_freq, ALLOCNO_NUM (thread1), ALLOCNO_REGNO (thread1), ALLOCNO_FREQ (thread1)); @@ -2184,6 +2195,9 @@ form_threads_from_colorable_allocno (ira_allocno_t a) ira_copy_t cp, next_cp; int cp_num = 0; + if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL) + fprintf (ira_dump_file, " Forming thread from allocno a%dr%d:\n", + ALLOCNO_NUM (a), ALLOCNO_REGNO (a)); for (cp = ALLOCNO_COPIES (a); cp != NULL; cp = next_cp) { if (cp->first == a) @@ -2505,7 +2519,13 @@ remove_allocno_from_bucket_and_push (ira_allocno_t allocno, bool colorable_p) static void push_only_colorable (void) { + if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL) + fprintf (ira_dump_file, " Forming thread from colorable bucket:\n"); form_threads_from_bucket (colorable_allocno_bucket); + for (ira_allocno_t a = colorable_allocno_bucket; + a != NULL; + a = ALLOCNO_COLOR_DATA (a)->next_bucket_allocno) + update_costs_from_prefs (a); sort_bucket (&colorable_allocno_bucket, bucket_allocno_compare_func); for (;colorable_allocno_bucket != NULL;) remove_allocno_from_bucket_and_push (colorable_allocno_bucket, true); @@ -2687,7 +2707,7 @@ pop_allocnos_from_stack (void) else if (assign_hard_reg (allocno, false)) { if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL) - fprintf (ira_dump_file, "assign reg %d\n", + fprintf (ira_dump_file, " assign reg %d\n", ALLOCNO_HARD_REGNO (allocno)); } else if (ALLOCNO_ASSIGNED_P (allocno)) @@ -3202,7 +3222,6 @@ color_allocnos (void) if (ALLOCNO_CLASS (a) != NO_REGS && ! empty_profitable_hard_regs (a)) { ALLOCNO_COLOR_DATA (a)->in_graph_p = true; - update_costs_from_prefs (a); update_conflict_allocno_hard_prefs (a); } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 69c3cac3d71..52919b9fbc8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-05-08 Vladimir Makarov + + * gcc.target/i386/pr92807-1.c: Improve the regex. + 2020-05-08 Iain Sandoe PR c++/95003 diff --git a/gcc/testsuite/gcc.target/i386/pr92807-1.c b/gcc/testsuite/gcc.target/i386/pr92807-1.c index 00f92930af9..02a0654dd5e 100644 --- a/gcc/testsuite/gcc.target/i386/pr92807-1.c +++ b/gcc/testsuite/gcc.target/i386/pr92807-1.c @@ -8,4 +8,4 @@ abs2 (unsigned int a) return (a+s)^s; } -/* { dg-final { scan-assembler-not "leal" } } */ +/* { dg-final { scan-assembler-not "leal\[\t \]*\[^(\]*\\((.*),\\1\\)" } } */