From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 64BA23858C52 for ; Tue, 8 Nov 2022 10:09:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 64BA23858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52b.google.com with SMTP id a5so21642698edb.11 for ; Tue, 08 Nov 2022 02:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Z9n7Ea2P14CqOLHdsK8Gn/y8hKe8TFCKsCOCFEpa7iQ=; b=jQyZvElnn6S97To97oETIzOQpJnYgDAYM6vofMzGWMApxFdVmzTUyyzp3NppyiCnky /4O5ctpQ0ObtluRUA6HSNKtaBxymVvn0ODurZTeDrteT0UyFDkyE/ZAjRt0GsqrdKm88 /8OiAe1s9LCzsDYLBnlGuM9b342cUWKe2ucg8wQRsMNIBcG4w5JfZbpbfVbBG0o2viOk saHjVrBC3xVU63M5JeZ/EVtsnVHEpF7705/2sreBE6D+Jk0oa0bxoxdMnlji3Qfwdnzc VZ2PWLaV4PvKljV1NzHbISeXiOgGIKZOFZygQKU80s+OS6SHsZ7dqLeBT/CRlxJtzaz2 f37w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z9n7Ea2P14CqOLHdsK8Gn/y8hKe8TFCKsCOCFEpa7iQ=; b=I97Gx7bNFrGzey3vBOmF6WRNvPAt1k6wj6W63NZA9o0gUDAFjTSrVwycAr0lnHgVs8 uXAueLtb+na9GODXy53xgdvipP+0hMDhs1SQgswOQ/9A5b/m0QHmX1AGAEimvpUNbNeu BWoTSX3OSFAe0MQXkDhslcglbT0aFA9i22gINo+lfs4Ir7R+W0NAHJVgwGN7E01YAYRN CBhvbZjugS8f2D7eHyjZ6XJWDJYUo9a1v3N//ffXqRE0LcmFrJfnW3c2zWQvpsySpoTY qomWptZY0SnU9LPzcbT04mHSuKi5lrKUnDjke6AcZtiTZJNW8LVKcbry9I1d+1jeJtvh gGiQ== X-Gm-Message-State: ACrzQf0zgIiPbtm1DCj5N5WMbmqM7ESReq2gmvjEf2U82lF3bdDjW1fR SbdcJEO/8BBSq1A370UumQ/LF1KrydHZ6TUIl14= X-Google-Smtp-Source: AMsMyM4jojQzGiMOGjrd095WKyV2VX4J/0QxZRdQL1Ua4S+/pnntrUuiCqRc7XcXcG4qpXW8YlHa2Et0xaUrA1n1l8w= X-Received: by 2002:a05:6402:550c:b0:443:7d15:d57f with SMTP id fi12-20020a056402550c00b004437d15d57fmr55022010edb.147.1667902180013; Tue, 08 Nov 2022 02:09:40 -0800 (PST) MIME-Version: 1.0 References: <454e83e7-e7a2-6e10-e051-b33c2d1b580d@linux.ibm.com> In-Reply-To: <454e83e7-e7a2-6e10-e051-b33c2d1b580d@linux.ibm.com> From: Richard Biener Date: Tue, 8 Nov 2022 11:09:28 +0100 Message-ID: Subject: Re: [PATCH] rtl: Try to remove EH edges after {pro,epi}logue generation [PR90259] To: "Kewen.Lin" Cc: GCC Patches , Segher Boessenkool , Peter Bergner , Eric Botcazou , Jeff Law Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Tue, Nov 8, 2022 at 3:49 AM Kewen.Lin wrote: > > 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? It looks reasonable - OK if the others CCed have no comments. Thanks, Richard. > 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 > > 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; > -- > 2.35.4