From patchwork Fri Feb 9 09:00:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 198792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp718132dyd; Fri, 9 Feb 2024 01:01:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFosY4U+u5A6dHC+knkeOeMpq62VEG4D7Zp/aNJAxXpaICm6hh8NtNtxkWca1ydgTrv3j5W X-Received: by 2002:a05:6102:1623:b0:46d:6f0c:b22a with SMTP id cu35-20020a056102162300b0046d6f0cb22amr880143vsb.27.1707469261884; Fri, 09 Feb 2024 01:01:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707469261; cv=pass; d=google.com; s=arc-20160816; b=WLA7EmIsbbq+gQgjuRrvde+qHHG9bZPl8GnDcGUtJhmXo75w3dOYjjAdoEdGgiyxGZ LBZehxAEq1ZLVQRFAPhQ8rsBwDRJimewDPp9QZpKOppGrQNuE/Yb1Z8QiC5oVFO8gKMZ CN4jcXw210w/15YWbHM1V+FgCmu0EDcB3SvEuPOQK929ciRYCpbB+n7VwsdIpPAUW6jM PXkhQBzdYUgxgBTeVMNeBSIxU2S70De+CqZO6Ib2bFKf7psJcqK4haALmRuMjdu4O7ar 9gAbfVBF+sEZp3Et9b8kuQFdf2qHDe8ZslrL8yNj53sGypMM0OgBk+aPB1kM5SoSx+AQ DbrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=0Ub6KiVaTPopir0iwM4qBu3V93+c16Qo53ye1LGu/vs=; fh=hMSQngm1gOFqk9oM5GrM3vXpSlTV2MLJhoRRhNKTwAo=; b=LGJobPyyU3fgcdKXG4mHq/vmClfqFAB2KXblxWysqSlE5fxNHKgCJm3D98fW3DY9Yx 2RuZio7t/Sq4Yr+Ie60ZwmFAOod9Lakd+trnFuqQrO2sqTWFxSOmY1SN6MdgwVRQNFX9 iVltun16ag2xopu8+gzHOVbO1rBHNmEEJKSGS1P5GfDJwPvR+tgVpRl3p19LvPpjcRJM Epnbu5N4UHtPbRses1fT35v1RpCj/jgQrNsnfm2IFpiyKwYN2i0qLHzxgJemvYOSXuye DY3jX5LKWlR7zaKIZNEPDsE7HDigLu9kh2fO26U8N+sMwNtmEqzP39at2E8q8BT4u9ll dKvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ag+IJN8d; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCUVEIwcMoR8PSCljW1GXpu30wW8OhhcQ0McEuc21gtbcOdDNIwsyshStBM3ODhESgK2se4GTAgPfxLSQ2Jrg6nOyrGj5Q== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fo12-20020ad45f0c000000b0068ca87dfeb7si1587228qvb.119.2024.02.09.01.01.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 01:01:01 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ag+IJN8d; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9174D385840E for ; Fri, 9 Feb 2024 09:01:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 24E7F3858403 for ; Fri, 9 Feb 2024 09:00:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24E7F3858403 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 24E7F3858403 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707469217; cv=none; b=CkNIErFqXndiAQHUcnSZ+y8JOQT4RoInj/tYRUfKHl4ouvK/jxqI1hME9VWJtUrZhTZUfCAJHF1oGdENCGeKaoiMEsZlctxji1qxFO21pRrrQys/Abgn7a659gt4VOc5H5Tj7caJwZ+iHiaREwXEb2Pnw12kH3VPmlcKh07Pu2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707469217; c=relaxed/simple; bh=ECQZ+dB7Mz2jleSUQTwgFuujn1a2Rrl5Vq1vKEHDw+o=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=hM2QoOKoVjGBQ/aL73C/dwb43MCo6o9gVN/+1LpmA9vgNymy9P7NxtUpWj2YYDAbrITMd7YErNh14K3CYOGZaioHanhJW66bfPUq5PuICBlNTbwkcV4OLzlVtOvPqkq5yaMiltWcM5dK9jI9L84GPjyrZ4RhuUSSFRQ026CBqVY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707469214; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=0Ub6KiVaTPopir0iwM4qBu3V93+c16Qo53ye1LGu/vs=; b=Ag+IJN8dDkglV67IWe7Pf8v8N4mNoySwPnTajJrpgt6B9OtoKoV7Kl86QVRAV0cTbkTDXy G5Rz50d5Cdsdk0LkCcawbP2gAziSfVxEb4+KEz8WZ6W1M2tg0MjTxEhO8QlVb0vu0UZS1+ +kLzb7XDR1is0s9yjnDfjjWGX+/EeEY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672-FHTqHKE7NaSQj3-Jey_zsA-1; Fri, 09 Feb 2024 04:00:11 -0500 X-MC-Unique: FHTqHKE7NaSQj3-Jey_zsA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF78228B68F7; Fri, 9 Feb 2024 09:00:10 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E64F40C9444; Fri, 9 Feb 2024 09:00:10 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 419907qm639964 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 9 Feb 2024 10:00:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 419907qY639963; Fri, 9 Feb 2024 10:00:07 +0100 Date: Fri, 9 Feb 2024 10:00:06 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up additions of EH edges [PR113818] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790411289080807292 X-GMAIL-MSGID: 1790411289080807292 Hi! Due to -fnon-call-exceptions the bitint lowering adds new EH edges in various places, so that the EH edge points from handling (e.g. load or store) of each of the limbs. The problem is that the EH edge destination as shown in the testcase can have some PHIs. If it is just a virtual PHI, no big deal, the pass uses TODO_update_ssa_only_virtuals, but if it has other PHIs, I think we need to copy the values from the preexisting corresponding EH edge (which is from the original stmt to the EH pad) to the newly added EH edge, so that the PHI arguments are the same rather than missing (which ICEs during checking at the end of the pass). This patch adds a function to do that and uses it whenever adding EH edges. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-09 Jakub Jelinek PR tree-optimization/113818 * gimple-lower-bitint.cc (add_eh_edge): New function. (bitint_large_huge::handle_load, bitint_large_huge::lower_mergeable_stmt, bitint_large_huge::lower_muldiv_stmt): Use it. * gcc.dg/bitint-89.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-02-08 14:33:36.033220098 +0100 +++ gcc/gimple-lower-bitint.cc 2024-02-08 17:29:38.182386934 +0100 @@ -1681,6 +1681,27 @@ bitint_large_huge::handle_cast (tree lhs return NULL_TREE; } +/* Add a new EH edge from SRC to EH_EDGE->dest, where EH_EDGE + is an older EH edge, and except for virtual PHIs duplicate the + PHI argument from the EH_EDGE to the new EH edge. */ + +static void +add_eh_edge (basic_block src, edge eh_edge) +{ + edge e = make_edge (src, eh_edge->dest, EDGE_EH); + e->probability = profile_probability::very_unlikely (); + for (gphi_iterator gsi = gsi_start_phis (eh_edge->dest); + !gsi_end_p (gsi); gsi_next (&gsi)) + { + gphi *phi = gsi.phi (); + tree lhs = gimple_phi_result (phi); + if (virtual_operand_p (lhs)) + continue; + const phi_arg_d *arg = gimple_phi_arg (phi, eh_edge->dest_idx); + add_phi_arg (phi, arg->def, e, arg->locus); + } +} + /* Helper function for handle_stmt method, handle a load from memory. */ tree @@ -1756,8 +1777,7 @@ bitint_large_huge::handle_load (gimple * if (eh_edge) { edge e = split_block (gsi_bb (m_gsi), g); - make_edge (e->src, eh_edge->dest, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, eh_edge); m_gsi = gsi_after_labels (e->dest); if (gsi_bb (save_gsi) == e->src) { @@ -1876,8 +1896,7 @@ bitint_large_huge::handle_load (gimple * { edge e = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e->dest); - make_edge (e->src, eh_edge->dest, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, eh_edge); } } if (conditional) @@ -1934,8 +1953,7 @@ normal_load: { edge e = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e->dest); - make_edge (e->src, eh_edge->dest, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, eh_edge); } if (tree_fits_uhwi_p (idx)) { @@ -2554,8 +2572,8 @@ bitint_large_huge::lower_mergeable_stmt { edge e = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e->dest); - make_edge (e->src, eh_pad, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, + find_edge (gimple_bb (stmt), eh_pad)); } } if (kind == bitint_prec_large) @@ -2633,8 +2651,8 @@ bitint_large_huge::lower_mergeable_stmt { edge e = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e->dest); - make_edge (e->src, eh_pad, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, + find_edge (gimple_bb (stmt), eh_pad)); } } if (new_bb) @@ -2777,8 +2795,7 @@ bitint_large_huge::lower_mergeable_stmt { edge e = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e->dest); - make_edge (e->src, eh_pad, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad)); } } if (kind == bitint_prec_huge && i == (bo_bit != 0)) @@ -2822,8 +2839,7 @@ bitint_large_huge::lower_mergeable_stmt { edge e = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e->dest); - make_edge (e->src, eh_pad, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad)); } } } @@ -3479,8 +3495,7 @@ bitint_large_huge::lower_muldiv_stmt (tr { edge e2 = split_block (gsi_bb (m_gsi), g); m_gsi = gsi_after_labels (e2->dest); - make_edge (e2->src, e1->dest, EDGE_EH)->probability - = profile_probability::very_unlikely (); + add_eh_edge (e2->src, e1); } } } --- gcc/testsuite/gcc.dg/bitint-89.c.jj 2024-02-08 17:35:01.693881442 +0100 +++ gcc/testsuite/gcc.dg/bitint-89.c 2024-02-08 17:34:39.555189760 +0100 @@ -0,0 +1,22 @@ +/* PR tree-optimization/113818 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-Os -fnon-call-exceptions -finstrument-functions-once" } */ + +int c, i; +void bar (int *); + +#if __BITINT_MAXWIDTH__ >= 129 +_BitInt(129) *a; +#else +_BitInt(63) *a; +#endif + +void +foo (void) +{ + if (c) + return; + int q; + a[i] = 0; + bar (&q); +}