From patchwork Thu Apr 14 13:29:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 52909 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B3323857C6F for ; Thu, 14 Apr 2022 13:29:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B3323857C6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649942976; bh=q1hpKCcXQY9cssQ1Jm8KMSrZIypztiFrt3+6m9gGFHo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HsMi20POD2PBiAyrWhfpzPWSbMp15M0Zbngxdv5/tcE1mefYXpe5IVgs7QvDHZN2z WxocvSahctlIRnrfwsRm8STo1Vj72Wdp2lDNdaX9IXWV/m8+IPeBReqTUyuClVtqUo s6ErrV2ei6dAbNQIKnWRoim3MwhGIYAhTYRd/tp4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id B6CBF385843E for ; Thu, 14 Apr 2022 13:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B6CBF385843E Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B63DC21611; Thu, 14 Apr 2022 13:29:05 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 967FE132C0; Thu, 14 Apr 2022 13:29:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dwSgI6EhWGLGRQAAMHmgww (envelope-from ); Thu, 14 Apr 2022 13:29:05 +0000 Date: Thu, 14 Apr 2022 15:29:05 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] rtl-optimization/105231 - distribute_notes and REG_EH_REGION MIME-Version: 1.0 Message-Id: <20220414132905.967FE132C0@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: ebotcazou@adacore.com, segher@kernel.crashing.org, rth@twiddle.net Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following mitigates a problem in combine distribute_notes which places an original REG_EH_REGION based on only may_trap_p which is good to test whether a non-call insn can possibly throw but not if actually it does or we care. That's something we decided at RTL expansion time where we possibly still know the insn evaluates to a constant. In fact, the REG_EH_REGION can only come from the original i3 and an assert is added to that effect. That means we only need to retain the note on i3 or, if that cannot trap, drop it but we should never move it to i2. If splitting of i3 ever becomes a problem here the insn split should be rejected instead. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. OK? 2022-04-14 Richard Biener PR rtl-optimization/105231 * combine.cc (distribute_notes): Assert that a REG_EH_REGION is from i3 and only keep it there or drop it if the insn can not trap. * gcc.dg/torture/pr105231.c: New testcase. --- gcc/combine.cc | 12 +++++------- gcc/testsuite/gcc.dg/torture/pr105231.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr105231.c diff --git a/gcc/combine.cc b/gcc/combine.cc index 53dcac92abc..ec53eda7595 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -14175,21 +14175,19 @@ distribute_notes (rtx notes, rtx_insn *from_insn, rtx_insn *i3, rtx_insn *i2, break; case REG_EH_REGION: + /* A REG_EH_REGION note can only ever come from i3. */ + gcc_assert (from_insn == i3); /* These notes must remain with the call or trapping instruction. */ if (CALL_P (i3)) place = i3; - else if (i2 && CALL_P (i2)) - place = i2; else { gcc_assert (cfun->can_throw_non_call_exceptions); + /* If i3 can still trap preserve the note, otherwise we've + combined things such that we can now prove that the + instructions can't trap. Drop the note in this case. */ if (may_trap_p (i3)) place = i3; - else if (i2 && may_trap_p (i2)) - place = i2; - /* ??? Otherwise assume we've combined things such that we - can now prove that the instructions can't trap. Drop the - note in this case. */ } break; diff --git a/gcc/testsuite/gcc.dg/torture/pr105231.c b/gcc/testsuite/gcc.dg/torture/pr105231.c new file mode 100644 index 00000000000..50459219c08 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr105231.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target int32plus } */ +/* { dg-require-effective-target dfp } */ +/* { dg-additional-options "-fsanitize-coverage=trace-pc -fnon-call-exceptions --param=max-cse-insns=1 -frounding-math" } */ +/* { dg-additional-options "-mstack-arg-probe" { target x86_64-*-* i?86-*-* } } */ + +void baz (int *); +void bar (double, double, _Decimal64); + +void +foo (void) +{ + int s __attribute__((cleanup (baz))); + bar (0xfffffffffffffffe, 0xebf3fff2fbebaf7f, 0xffffffffffffff); +}