From patchwork Fri Oct 18 09:06:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1179221 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-511273-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="iB3bCG/N"; dkim-atps=neutral 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 46vgCR0sGfz9sPJ for ; Fri, 18 Oct 2019 20:07:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:mime-version:content-transfer-encoding :message-id; q=dns; s=default; b=mw97vmJjiHrSzeb53FK7XDlNKjyBTup DSLfGeOPDjMTyY5dqpu4GeuD4StZgT6R9hLAMAc+OV4CP8MNBHt4axYJ0/XnaPN6 A9e6/R1m+7KVtUCzWp2RF3cbRtPIur8c9Reo7U/ui1GuO1bppDPNooQrZVKeNiCR 2b72bJ4l5cBM= 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:from :to:cc:subject:date:mime-version:content-transfer-encoding :message-id; s=default; bh=4deCZwvoPNYWeO8Z1ZD1wtIYQz4=; b=iB3bC G/Nd+/brjgQVqqoWJxVljEarWmU7SkA8R4Wyca+FVwggwVbrshmU/pjoZyL1+mvA C/o+F+6g9IcaLpn6rm0EI5G0wn/ZE96ldOYJ2j9OUzIXW0a2rj1jC9SOiI1OO2Vx U5Zlw3b4Re0rvykQSWBe+wqTm3C2JudrEUby6g= Received: (qmail 17783 invoked by alias); 18 Oct 2019 09:07:07 -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 17773 invoked by uid 89); 18 Oct 2019 09:07:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=unavailable version=3.3.1 spammy= X-HELO: mx0b-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0b-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Oct 2019 09:07:05 +0000 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9I8vKnQ060439 for ; Fri, 18 Oct 2019 05:07:04 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vq0ha16u1-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 18 Oct 2019 05:07:01 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 18 Oct 2019 10:06:55 +0100 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 18 Oct 2019 10:06:53 +0100 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9I96J7a36372894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2019 09:06:20 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 93B59A4054; Fri, 18 Oct 2019 09:06:51 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E044A405B; Fri, 18 Oct 2019 09:06:51 +0000 (GMT) Received: from white.boeblingen.de.ibm.com (unknown [9.145.103.145]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2019 09:06:51 +0000 (GMT) From: Ilya Leoshkevich To: gcc-patches@gcc.gnu.org, segher@gcc.gnu.org, jakub@redhat.com Cc: krebbel@linux.ibm.com, Ilya Leoshkevich Subject: [PATCH] Move jump threading before reload Date: Fri, 18 Oct 2019 11:06:45 +0200 MIME-Version: 1.0 x-cbid: 19101809-0028-0000-0000-000003AB3473 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19101809-0029-0000-0000-0000246D54AB Message-Id: <20191018090645.22404-1-iii@linux.ibm.com> X-IsSubscribed: yes Bootstrapped and regtested on x86_64-redhat-linux, s390x-redhat-linux and ppc64le-redhat-linux. The offending patch is in gcc-9_1_0-release and gcc-9_2_0-release - do I need to backport this fix to gcc-9-branch? r266734 has introduced a new instance of jump threading pass in order to take advantage of opportunities that combine opens up. It was perceived back then that it was beneficial to delay it after reload, since that might produce even more such opportunities. Unfortunately jump threading interferes with hot/cold partitioning. In the code from PR92007, it converts the following +-------------------------- 2/HOT ------------------------+ | | v v 3/HOT --> 5/HOT --> 8/HOT --> 11/COLD --> 6/HOT --EH--> 16/HOT | ^ | | +-------------------------------+ into the following: +---------------------- 2/HOT ------------------+ | | v v 3/HOT --> 8/HOT --> 11/COLD --> 6/COLD --EH--> 16/HOT This makes hot bb 6 dominated by cold bb 11, and because of this fixup_partitions makes bb 6 cold as well, which in turn makes EH edge 6->16 a crossing one. Not only can't we have crossing EH edges, we are also not allowed to introduce new crossing edges after reload in general, since it might require extra registers on some targets. Therefore, move the jump threading pass between combine and hot/cold partitioning. Building SPEC 2006 and SPEC 2017 with the old and the new code indicates that: * When doing jump threading right after reload, 3889 edges are threaded. * When doing jump threading right after combine, 3918 edges are threaded. This means this change will not introduce performance regressions. gcc/ChangeLog: 2019-10-17 Ilya Leoshkevich PR rtl-optimization/92007 * cfgcleanup.c (thread_jump): Add an assertion that we don't call it after reload if hot/cold partitioning has been done. (class pass_postreload_jump): Rename to pass_jump_after_combine. (make_pass_postreload_jump): Rename to make_pass_jump_after_combine. * passes.def(pass_postreload_jump): Move before reload, rename to pass_jump_after_combine. * tree-pass.h (make_pass_postreload_jump): Rename to make_pass_jump_after_combine. gcc/testsuite/ChangeLog: 2019-10-17 Ilya Leoshkevich PR rtl-optimization/92007 * g++.dg/opt/pr92007.C: New test (from Arseny Solokha). --- gcc/cfgcleanup.c | 22 +++++++++++--------- gcc/passes.def | 2 +- gcc/testsuite/g++.dg/opt/pr92007.C | 32 ++++++++++++++++++++++++++++++ gcc/tree-pass.h | 2 +- 4 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr92007.C diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c index ced7e0a4283..835f7d79ea4 100644 --- a/gcc/cfgcleanup.c +++ b/gcc/cfgcleanup.c @@ -259,6 +259,10 @@ thread_jump (edge e, basic_block b) bool failed = false; reg_set_iterator rsi; + /* Jump threading may cause fixup_partitions to introduce new crossing edges, + which is not allowed after reload. */ + gcc_checking_assert (!reload_completed || !crtl->has_bb_partition); + if (b->flags & BB_NONTHREADABLE_BLOCK) return NULL; @@ -3280,10 +3284,10 @@ make_pass_jump (gcc::context *ctxt) namespace { -const pass_data pass_data_postreload_jump = +const pass_data pass_data_jump_after_combine = { RTL_PASS, /* type */ - "postreload_jump", /* name */ + "jump_after_combine", /* name */ OPTGROUP_NONE, /* optinfo_flags */ TV_JUMP, /* tv_id */ 0, /* properties_required */ @@ -3293,20 +3297,20 @@ const pass_data pass_data_postreload_jump = 0, /* todo_flags_finish */ }; -class pass_postreload_jump : public rtl_opt_pass +class pass_jump_after_combine : public rtl_opt_pass { public: - pass_postreload_jump (gcc::context *ctxt) - : rtl_opt_pass (pass_data_postreload_jump, ctxt) + pass_jump_after_combine (gcc::context *ctxt) + : rtl_opt_pass (pass_data_jump_after_combine, ctxt) {} /* opt_pass methods: */ virtual unsigned int execute (function *); -}; // class pass_postreload_jump +}; // class pass_jump_after_combine unsigned int -pass_postreload_jump::execute (function *) +pass_jump_after_combine::execute (function *) { cleanup_cfg (flag_thread_jumps ? CLEANUP_THREADING : 0); return 0; @@ -3315,9 +3319,9 @@ pass_postreload_jump::execute (function *) } // anon namespace rtl_opt_pass * -make_pass_postreload_jump (gcc::context *ctxt) +make_pass_jump_after_combine (gcc::context *ctxt) { - return new pass_postreload_jump (ctxt); + return new pass_jump_after_combine (ctxt); } namespace { diff --git a/gcc/passes.def b/gcc/passes.def index 8999ceec636..798a391bd35 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -439,6 +439,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_ud_rtl_dce); NEXT_PASS (pass_combine); NEXT_PASS (pass_if_after_combine); + NEXT_PASS (pass_jump_after_combine); NEXT_PASS (pass_partition_blocks); NEXT_PASS (pass_outof_cfg_layout_mode); NEXT_PASS (pass_split_all_insns); @@ -455,7 +456,6 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_reload); NEXT_PASS (pass_postreload); PUSH_INSERT_PASSES_WITHIN (pass_postreload) - NEXT_PASS (pass_postreload_jump); NEXT_PASS (pass_postreload_cse); NEXT_PASS (pass_gcse2); NEXT_PASS (pass_split_after_reload); diff --git a/gcc/testsuite/g++.dg/opt/pr92007.C b/gcc/testsuite/g++.dg/opt/pr92007.C new file mode 100644 index 00000000000..9434cc929dd --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr92007.C @@ -0,0 +1,32 @@ +// PR rtl-optimization/92007 +// { dg-do compile } +// { dg-options "-O2 -fno-tree-dominator-opts -fno-tree-forwprop --param max-cse-insns=0 -Wno-return-type -std=gnu++98 -freorder-blocks-and-partition" } + +void +sb (int *); + +class d4 { +public: + ~d4(); + void gb (); + int op () { return no; } + int wl () { return tf; } + bool ee () try { gb (); } catch (...) { return false; } + bool b1 () { return (tf == no) ? false : ee (); } + +private: + int no, tf; +}; + +void +hs (int *v9) +{ + d4 p6; + + p6.gb (); + if (p6.op () > p6.wl ()) + { + p6.b1 (); + sb (v9); + } +} diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 85b1c828f3a..a987661530e 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -564,6 +564,7 @@ extern rtl_opt_pass *make_pass_stack_ptr_mod (gcc::context *ctxt); extern rtl_opt_pass *make_pass_initialize_regs (gcc::context *ctxt); extern rtl_opt_pass *make_pass_combine (gcc::context *ctxt); extern rtl_opt_pass *make_pass_if_after_combine (gcc::context *ctxt); +extern rtl_opt_pass *make_pass_jump_after_combine (gcc::context *ctxt); extern rtl_opt_pass *make_pass_ree (gcc::context *ctxt); extern rtl_opt_pass *make_pass_partition_blocks (gcc::context *ctxt); extern rtl_opt_pass *make_pass_match_asm_constraints (gcc::context *ctxt); @@ -581,7 +582,6 @@ extern rtl_opt_pass *make_pass_clean_state (gcc::context *ctxt); extern rtl_opt_pass *make_pass_branch_prob (gcc::context *ctxt); extern rtl_opt_pass *make_pass_value_profile_transformations (gcc::context *ctxt); -extern rtl_opt_pass *make_pass_postreload_jump (gcc::context *ctxt); extern rtl_opt_pass *make_pass_postreload_cse (gcc::context *ctxt); extern rtl_opt_pass *make_pass_gcse2 (gcc::context *ctxt); extern rtl_opt_pass *make_pass_split_after_reload (gcc::context *ctxt);