From patchwork Thu Nov 23 13:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 168952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp461967vqx; Thu, 23 Nov 2023 05:57:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjGfRHgHo2Ix8vMk7YIRbk3tlMuQT16ECk8nDYVNszoBTxF8u5U/u2hFi04RI80gUrj05u X-Received: by 2002:ac8:4e89:0:b0:419:50d0:cf5a with SMTP id 9-20020ac84e89000000b0041950d0cf5amr6475899qtp.2.1700747819847; Thu, 23 Nov 2023 05:56:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700747819; cv=pass; d=google.com; s=arc-20160816; b=n7kqRR+96DKf+WidB2jviAxN4BuNe1MpZQG//FzljTmRVCJWNU75gGk1TU+ZSf2HLf jmyOGzPMdEhSMFY4R5XXvqIVYlEEfL5E374Y2ubvX1FP3VG1FWQR2Bpw2zZc8b0Sz60P 0r6yboGHcncY5RE2wVLIW/ilGatPLN77jOKQpGFSIaT0cJ9mV88VbYvRdVH06ZbuSYgl iVwhcVez+i1voS5NShaazHq+slG/IB0p+Hb/DW3/gzUaFTpSpW4iLz5UVHq9RnW2hd8D JICGePIQEdCbIykh14lzRHMh2yWK2BOHNQb8Avi11Efu6uMIAKwIkB/yKfAXqZuISHix xrxA== 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:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=0Bz4rWJd+Iy2DzxvRRk5LuD53C/vsfHeRN+OgPWaQOA=; fh=tv6DOCIqeNXqkPV0CQ2Joq3XuSytDjENzghaoAc7oww=; b=fzkeW7hLr1gzAiIQ2ZcFAhSTqee6NUQcAPNeYHs4fbAiafBg9ynBjP+8qWbFB5Ah0L vaqA7FyG72wzl06ytgxYZ03x0NU8RERPcqmcQDyz/xHC3xsNpvqCVwgHoRDkqix5hgQJ gxbpL5tO4D59/xLJ11GgwB92H/fmWcMHDd1AnTh+LzFHQPVAO5m9ad0YffAvtB/r1qHH Gf7IBnfdwGMnKz4ii2bFrzd0swId0y3QqeL+U2DY/o733C37UhuoV4frLpDSPs1q1Gqg lahr26psbNCVVfNQBnG2ZeEpXguldYRsx1IqKyO7SqRsZ6bouYPpfVoJEnNXbzvgm2qD UvXw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZYvcyOfH; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u24-20020a05622a199800b0041816224c33si1189214qtc.384.2023.11.23.05.56.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:56:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZYvcyOfH; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 760A23857C51 for ; Thu, 23 Nov 2023 13:56:59 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id A64D63858D33 for ; Thu, 23 Nov 2023 13:56:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A64D63858D33 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 A64D63858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700747796; cv=none; b=ZQvayjWbC1iXd/b6q4whPgwB2kRvmcXfwH3wqO6lyMtTFLx6cxE+55aFlP+D1Oeq5qJH5dCnvY31D58mFFXb84nLeSlA6gvX5rbdRFnSrrwYx3L/21Hol7I9rNrB2CnfdTlIIcEI70LY9k6l2I0iUW7cuWBItweqEj9dfwFLu40= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700747796; c=relaxed/simple; bh=/4mflT0vyN3kKuAxQCGQWF4MHY1yYl/Cwauad23eZyE=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=HYi6hM/aNd0yZO28JsTB1OKCwWGj0G6kv6aLOf8UjCMJAYoG9oeKDdSdqHM57OvVyHCLzAF0ovsX6Lgg4oQoi9Ri3KhLKzz4ht6G/tVn6wW2RSC0rqOkKpMwvB5Q9AiVTAeIkC9k3f97XJt5wzfyM5XnzQ/YJ+9ni2zByWrm59o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700747794; 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:in-reply-to:in-reply-to: references:references; bh=0Bz4rWJd+Iy2DzxvRRk5LuD53C/vsfHeRN+OgPWaQOA=; b=ZYvcyOfHvh9KZGvtFjieR2OknzS64DmWFI4cc9kdhF9w28R0rRdR2N0M8X9oXshMkj8Dye iVzMcwDKZkqW3vJYMO2XPbmM3I8VkpeZHP22j1gdNlhqcZkAMniT44qCN+iAOKJ7LgAs87 EW5/Dk8vY30MKapK1rWMhPM1fjsEals= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-YZR-LaEWNIums8rLOBxXVQ-1; Thu, 23 Nov 2023 08:56:31 -0500 X-MC-Unique: YZR-LaEWNIums8rLOBxXVQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 6184E881B61; Thu, 23 Nov 2023 13:56:31 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 247DF2026D4C; Thu, 23 Nov 2023 13:56:31 +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 3ANDuSob925773 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Nov 2023 14:56:28 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3ANDuRtR925772; Thu, 23 Nov 2023 14:56:27 +0100 Date: Thu, 23 Nov 2023 14:56:27 +0100 From: Jakub Jelinek To: Richard Biener Cc: Richard Biener , gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint, v3: Fix up -fnon-call-exceptions bit-field load lowering [PR112668] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H4, 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: 1783363345704353825 X-GMAIL-MSGID: 1783363345704353825 On Thu, Nov 23, 2023 at 01:10:02PM +0100, Richard Biener wrote: > Looks a bit better. As for constructing a gsi_end_p () iterator for a > basic-block > I'd simply add a new gsi_end_{bb,seq} ({basic_block,gimple_seq}). Ok, here it is (just used gsi_end without _seq suffix for gimple_seq & because it is then consistent with gsi_start/gsi_last etc.). 2023-11-23 Jakub Jelinek PR middle-end/112668 * gimple-iterator.h (gsi_end, gsi_end_bb): New inline functions. * gimple-lower-bitint.cc (bitint_large_huge::handle_cast): After temporarily adding statements after m_init_gsi, update m_init_gsi such that later additions after it will be after the added statements. (bitint_large_huge::handle_load): Likewise. When splitting gsi_bb (m_init_gsi) basic block, update m_preheader_bb if needed and update saved m_gsi as well if needed. (bitint_large_huge::lower_mergeable_stmt, bitint_large_huge::lower_comparison_stmt, bitint_large_huge::lower_mul_overflow, bitint_large_huge::lower_bit_query): Use gsi_end_bb. * gcc.dg/bitint-40.c: New test. Jakub --- gcc/gimple-iterator.h.jj 2023-04-22 10:23:40.628612517 +0200 +++ gcc/gimple-iterator.h 2023-11-23 14:46:28.371861488 +0100 @@ -169,6 +169,41 @@ gsi_last_bb (basic_block bb) return i; } +/* Return a new iterator pointing to before the first statement or after + last statement (depending on whether adding statements after it or before it) + in a GIMPLE_SEQ. */ + +inline gimple_stmt_iterator +gsi_end (gimple_seq &seq) +{ + gimple_stmt_iterator i; + gimple *g = gimple_seq_last (seq); + + i.ptr = NULL; + i.seq = &seq; + i.bb = g ? gimple_bb (g) : NULL; + + return i; +} + +/* Return a new iterator pointing to before the first statement or after + last statement (depending on whether adding statements after it or before it) + in basic block BB. */ + +inline gimple_stmt_iterator +gsi_end_bb (basic_block bb) +{ + gimple_stmt_iterator i; + gimple_seq *seq; + + seq = bb_seq_addr (bb); + i.ptr = NULL; + i.seq = seq; + i.bb = bb; + + return i; +} + /* Return true if I is at the end of its sequence. */ inline bool --- gcc/gimple-lower-bitint.cc.jj 2023-11-23 12:55:16.967225422 +0100 +++ gcc/gimple-lower-bitint.cc 2023-11-23 14:30:02.830662509 +0100 @@ -1294,6 +1294,11 @@ bitint_large_huge::handle_cast (tree lhs g = gimple_build_assign (n, RSHIFT_EXPR, t, lpm1); insert_before (g); m_data[save_data_cnt + 1] = add_cast (m_limb_type, n); + m_init_gsi = m_gsi; + if (gsi_end_p (m_init_gsi)) + m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi)); + else + gsi_prev (&m_init_gsi); m_gsi = save_gsi; } else if (m_upwards_2limb * limb_prec < TYPE_PRECISION (rhs_type)) @@ -1523,6 +1528,11 @@ bitint_large_huge::handle_cast (tree lhs insert_before (g); rext = add_cast (m_limb_type, gimple_assign_lhs (g)); } + m_init_gsi = m_gsi; + if (gsi_end_p (m_init_gsi)) + m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi)); + else + gsi_prev (&m_init_gsi); m_gsi = save_gsi; } tree t; @@ -1687,9 +1697,23 @@ bitint_large_huge::handle_load (gimple * edge e = split_block (gsi_bb (m_gsi), g); make_edge (e->src, eh_edge->dest, EDGE_EH)->probability = profile_probability::very_unlikely (); - m_init_gsi.bb = e->dest; + m_gsi = gsi_after_labels (e->dest); + if (gsi_bb (save_gsi) == e->src) + { + if (gsi_end_p (save_gsi)) + save_gsi = gsi_end_bb (e->dest); + else + save_gsi = gsi_for_stmt (gsi_stmt (save_gsi)); + } + if (m_preheader_bb == e->src) + m_preheader_bb = e->dest; } } + m_init_gsi = m_gsi; + if (gsi_end_p (m_init_gsi)) + m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi)); + else + gsi_prev (&m_init_gsi); m_gsi = save_gsi; tree out; prepare_data_in_out (iv, idx, &out); @@ -2359,11 +2383,7 @@ bitint_large_huge::lower_mergeable_stmt edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); edge_bb = e->src; if (kind == bitint_prec_large) - { - m_gsi = gsi_last_bb (edge_bb); - if (!gsi_end_p (m_gsi)) - gsi_next (&m_gsi); - } + m_gsi = gsi_end_bb (edge_bb); } else m_after_stmt = stmt; @@ -2816,9 +2836,7 @@ bitint_large_huge::lower_comparison_stmt gsi_prev (&gsi); edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); edge_bb = e->src; - m_gsi = gsi_last_bb (edge_bb); - if (!gsi_end_p (m_gsi)) - gsi_next (&m_gsi); + m_gsi = gsi_end_bb (edge_bb); edge *edges = XALLOCAVEC (edge, cnt * 2); for (unsigned i = 0; i < cnt; i++) @@ -4288,9 +4306,7 @@ bitint_large_huge::lower_mul_overflow (t gsi_prev (&gsi); edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); edge_bb = e->src; - m_gsi = gsi_last_bb (edge_bb); - if (!gsi_end_p (m_gsi)) - gsi_next (&m_gsi); + m_gsi = gsi_end_bb (edge_bb); tree cmp = build_zero_cst (m_limb_type); for (unsigned i = 0; i < cnt; i++) @@ -4560,11 +4576,7 @@ bitint_large_huge::lower_bit_query (gimp edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); edge_bb = e->src; if (kind == bitint_prec_large) - { - m_gsi = gsi_last_bb (edge_bb); - if (!gsi_end_p (m_gsi)) - gsi_next (&m_gsi); - } + m_gsi = gsi_end_bb (edge_bb); bqp = XALLOCAVEC (struct bq_details, cnt); } else @@ -4717,9 +4729,7 @@ bitint_large_huge::lower_bit_query (gimp gsi_prev (&gsi); edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi)); edge_bb = e->src; - m_gsi = gsi_last_bb (edge_bb); - if (!gsi_end_p (m_gsi)) - gsi_next (&m_gsi); + m_gsi = gsi_end_bb (edge_bb); if (ifn == IFN_CLZ) bqp = XALLOCAVEC (struct bq_details, cnt); --- gcc/testsuite/gcc.dg/bitint-40.c.jj 2023-11-23 14:22:48.328769734 +0100 +++ gcc/testsuite/gcc.dg/bitint-40.c 2023-11-23 14:22:48.328769734 +0100 @@ -0,0 +1,29 @@ +/* PR middle-end/112668 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -fnon-call-exceptions" } */ + +#if __BITINT_MAXWIDTH__ >= 156 +struct T156 { _BitInt(156) a : 2; unsigned _BitInt(156) b : 135; _BitInt(156) c : 2; }; +extern void foo156 (struct T156 *); + +unsigned _BitInt(156) +bar156 (int i) +{ + struct T156 r156[12]; + foo156 (&r156[0]); + return r156[i].b; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 495 +struct T495 { _BitInt(495) a : 2; unsigned _BitInt(495) b : 471; _BitInt(495) c : 2; }; +extern void foo495 (struct T495 *r495); + +unsigned _BitInt(495) +bar495 (int i) +{ + struct T495 r495[12]; + foo495 (r495); + return r495[i].b; +} +#endif