From patchwork Tue Nov 8 02:48:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1701055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=mAW3Qng2; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5sy45bfzz1yqS for ; Tue, 8 Nov 2022 13:49:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E4F13858433 for ; Tue, 8 Nov 2022 02:49:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E4F13858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667875768; bh=qJjjq3qbDlhYnJPpJvTeoZzMKgUU/J7OOhW1EuK0iSk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mAW3Qng2F89HRxr0q9lWhYBH+eOfYgsqWJOBUrluvKNm32vdNQwME7f/rybFE2mzg goZC2cuKDYpfxzzcFInXjuhFRMaULV0bEXDeMfjJ1ttmX9toMzo6xdYatZTkD2KSax IuSzHWFSWEdFPbBsdPBrIpxxlrENPOiWMYmhJPwk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 55E183858D39 for ; Tue, 8 Nov 2022 02:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55E183858D39 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A81mNFR022200; Tue, 8 Nov 2022 02:49:06 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kp1w915b3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 02:49:05 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2A82n5Gb008671; Tue, 8 Nov 2022 02:49:05 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kp1w915ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 02:49:05 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2A82a94t022273; Tue, 8 Nov 2022 02:49:03 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03ams.nl.ibm.com with ESMTP id 3kngqgbed7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Nov 2022 02:49:02 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2A82n0WS7864926 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Nov 2022 02:49:00 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6BC05204F; Tue, 8 Nov 2022 02:49:00 +0000 (GMT) Received: from [9.197.244.202] (unknown [9.197.244.202]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8462B5204E; Tue, 8 Nov 2022 02:48:58 +0000 (GMT) Message-ID: <454e83e7-e7a2-6e10-e051-b33c2d1b580d@linux.ibm.com> Date: Tue, 8 Nov 2022 10:48:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: GCC Patches Cc: Richard Biener , Segher Boessenkool , Peter Bergner , Eric Botcazou , Jeff Law Subject: [PATCH] rtl: Try to remove EH edges after {pro,epi}logue generation [PR90259] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: lljOHhAMlyJOYoflkHfcrdt_WAI9sfkR X-Proofpoint-ORIG-GUID: ORXiCF9hW1Cc67OUAPnc2zX0vCv2YXES X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-07_11,2022-11-07_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=981 adultscore=0 mlxscore=0 clxscore=1011 lowpriorityscore=0 bulkscore=0 impostorscore=0 phishscore=0 priorityscore=1501 spamscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080011 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, After prologue and epilogue generation, the judgement on whether one memory access onto stack frame may trap or not could change, since we get more exact stack information by now. As PR90259 shows, some memory access becomes impossible to trap any more after prologue and epilogue generation, it can make subsequent optimization be able to remove it if safe, but it results in unexpected control flow status due to REG_EH_REGION note missing. This patch proposes to try to remove EH edges with function purge_all_dead_edges after prologue and epilogue generation, it simplifies CFG as early as we can and don't need any fixup in downstream passes. CFG simplification result with PR90259's case as example: *before* 18: %1:TF=call [`__gcc_qdiv'] argc:0 REG_EH_REGION 0x2 77: NOTE_INSN_BASIC_BLOCK 3 19: NOTE_INSN_DELETED 20: NOTE_INSN_DELETED 110: [%31:SI+0x20]=%1:DF REG_EH_REGION 0x2 116: NOTE_INSN_BASIC_BLOCK 4 111: [%31:SI+0x28]=%2:DF REG_EH_REGION 0x2 22: NOTE_INSN_BASIC_BLOCK 5 108: %0:DF=[%31:SI+0x20] REG_EH_REGION 0x2 117: NOTE_INSN_BASIC_BLOCK 6 109: %1:DF=[%31:SI+0x28] REG_EH_REGION 0x2 79: NOTE_INSN_BASIC_BLOCK 7 26: [%31:SI+0x18]=%0:DF 104: pc=L69 105: barrier *after* 18: %1:TF=call [`__gcc_qdiv'] argc:0 REG_EH_REGION 0x2 77: NOTE_INSN_BASIC_BLOCK 3 19: NOTE_INSN_DELETED 20: NOTE_INSN_DELETED 110: [%31:SI+0x20]=%1:DF 111: [%31:SI+0x28]=%2:DF 108: %0:DF=[%31:SI+0x20] 109: %1:DF=[%31:SI+0x28] 26: [%31:SI+0x18]=%0:DF 104: pc=L69 105: barrier Bootstrapped and regtested on x86_64-redhat-linux, aarch64-linux-gnu and powerpc64{,le}-linux-gnu. Is it ok for trunk? BR, Kewen ----- PR rtl-optimization/90259 gcc/ChangeLog: * function.cc (rest_of_handle_thread_prologue_and_epilogue): Add parameter fun, and call function purge_all_dead_edges. (pass_thread_prologue_and_epilogue::execute): Name unamed parameter as fun, and use it for rest_of_handle_thread_prologue_and_epilogue. gcc/testsuite/ChangeLog: * g++.target/powerpc/pr90259.C: New. --- gcc/function.cc | 13 ++- gcc/testsuite/g++.target/powerpc/pr90259.C | 103 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.target/powerpc/pr90259.C -- 2.35.4 diff --git a/gcc/function.cc b/gcc/function.cc index 6474a663b30..3757ded547d 100644 --- a/gcc/function.cc +++ b/gcc/function.cc @@ -6540,7 +6540,7 @@ make_pass_leaf_regs (gcc::context *ctxt) } static unsigned int -rest_of_handle_thread_prologue_and_epilogue (void) +rest_of_handle_thread_prologue_and_epilogue (function *fun) { /* prepare_shrink_wrap is sensitive to the block structure of the control flow graph, so clean it up first. */ @@ -6557,6 +6557,13 @@ rest_of_handle_thread_prologue_and_epilogue (void) Fix that up. */ fixup_partitions (); + /* After prologue and epilogue generation, the judgement on whether + one memory access onto stack frame may trap or not could change, + since we get more exact stack information by now. So try to + remove any EH edges here, see PR90259. */ + if (fun->can_throw_non_call_exceptions) + purge_all_dead_edges (); + /* Shrink-wrapping can result in unreachable edges in the epilogue, see PR57320. */ cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0); @@ -6625,9 +6632,9 @@ public: {} /* opt_pass methods: */ - unsigned int execute (function *) final override + unsigned int execute (function * fun) final override { - return rest_of_handle_thread_prologue_and_epilogue (); + return rest_of_handle_thread_prologue_and_epilogue (fun); } }; // class pass_thread_prologue_and_epilogue diff --git a/gcc/testsuite/g++.target/powerpc/pr90259.C b/gcc/testsuite/g++.target/powerpc/pr90259.C new file mode 100644 index 00000000000..db75ac7fe02 --- /dev/null +++ b/gcc/testsuite/g++.target/powerpc/pr90259.C @@ -0,0 +1,103 @@ +/* { dg-require-effective-target long_double_ibm128 } */ +/* { dg-options "-O2 -ffloat-store -fgcse -fnon-call-exceptions -fno-forward-propagate -fno-omit-frame-pointer -fstack-protector-all" } */ +/* { dg-add-options long_double_ibm128 } */ + +/* Verify there is no ICE. */ + +template struct b +{ + static constexpr int c = a; +}; +template using d = b; +struct e +{ + int f; + int + g () + { + return __builtin_ceil (f / (long double) h); + } + float h; +}; +template using k = d; +template class n +{ +public: + e ae; + void af (); +}; +template +void +n::af () +{ + ae.g (); +} +template using m = int; +template ::c>> +using aj = n; +struct o +{ + void + af () + { + al.af (); + } + aj al; +}; +template class am; +template class ao +{ +protected: + static i *ap (int); +}; +template class p; +template class p : ao +{ +public: + static ar + as (const int &p1, j...) + { + (*ao::ap (p1)) (j ()...); + } +}; +template class am +{ + template using av = int; + +public: + template , void>, + typename = av> + am (i); + using aw = ar (*) (const int &, j...); + aw ax; +}; +template +template +am::am (i) +{ + ax = p::as; +} +struct G +{ + void ba (am); +}; +struct q +{ + q () + { + G a; + a.ba (r ()); + } + struct r + { + void + operator() (o p1) + try + { + p1.af (); + } + catch (int) + { + } + }; +} s;