From patchwork Thu Nov 23 09:42:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 168825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp327654vqx; Thu, 23 Nov 2023 01:43:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+6x3XGyIoVYcbNehvk+LykrkfU648c73TU6txzOQR9Z2CfZ8Nmgr+PULim/ZGVhn5MjuR X-Received: by 2002:a81:7745:0:b0:5ca:4db5:cb76 with SMTP id s66-20020a817745000000b005ca4db5cb76mr4809140ywc.34.1700732583612; Thu, 23 Nov 2023 01:43:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700732583; cv=pass; d=google.com; s=arc-20160816; b=iAhdoeLtoOdzNltumMyrTKJRzTk7y/kWZDmZYyRZWgozs0OfXdMPy8gwVhwIoGhVHX EaBcnnbI5KYhUJIynHboKCerpvy1EQEOKR9fVkj0WXDjkQlcmS/cq/gYoxlyB77fhp0Q j7JGcHy5ERdHzTJ5U3LYtUd0+xGWuliSL/o1EUdTMfRYeuZpuLkzOxqHn2QwBkbCC2Of QgktRE91EDACUFXrePBKQXBAy+nCvA17dTId8gp2rdiIJsFoza7Erh+alpyFYrebALic P7uhfXT8JM81l6WKYUAENGyhwHfdDbLDQO8Xdl1yMiQIW1ZtgIxRVdQh/spp3nU2Nwav oA0Q== 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=MYG7EOawCsalqHQjO7r6fWUAmQwiesUHyef10i6e7jU=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=DdRkqQjL7wdbI75DFwggXWswjiFjIg8tabCPBhzqP4xyrcKUDgm/8eAb8FeXPGttT4 4eoExKf9TJuwqLNyfXMCIWPptBJhkKyZTJ+d0b/ojW8wgCM8MW1pALi0Yqk0I+Agslzo uGQ0iTQxmPdEPKGOgZh3yQAm4ydEXVMxy2s3ZSwsg7Vx8jIVrvxVIKVaGTdN1d3bjBr2 7t+mLQKai0DCzj8QKRv8pDkRgjQ1us+AnMiG0EfZFXwfVncN5FmRy3Ezouj5QmZ7HvUj PE5VXk3I2b7CqnkAZjO7liOWA61Kpias3G/tiJZZxKxx9Iukrc2/2EK4Um5WE+/fA9A0 1sXg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iJ2k7ff1; 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 ff16-20020a0562140bd000b00671020e6d2fsi785383qvb.315.2023.11.23.01.43.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 01:43:03 -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=iJ2k7ff1; 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 5E2803857B9C for ; Thu, 23 Nov 2023 09:43:03 +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 EC6F53858C52 for ; Thu, 23 Nov 2023 09:42:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC6F53858C52 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 EC6F53858C52 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=1700732561; cv=none; b=YTEwBPx+oVnwP+bGo+ED744aMpnHIy16MzOpEZPkT2VqS99TGziDbjcqAjgOHB2Ev9zET7g3prTQ6LcB1ejXVjaOiydSmkWlXETUfcw7AnXIQv0WFZ36a+q0aGYGKDRc7LDCCYJE/o5ATPQ2TFB5gR0GDiYp7lPm5xmgz/NutXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700732561; c=relaxed/simple; bh=t5e7jLQlosz22/eKtNBGF03/9ZnGrgZH2YWyCGPGYBI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=cwKY7aou3yiQH4d5p/zAin08RGu4wQ6CXwTHxcTXSRQ4OWDY/LvOvnptIRBh6HBpFUWhfGgye/HZ1H8dzu1u5svJ4zCLIFDNdvObGNAABW2h69H1ZD7t0io4YtNvSQq11QwlPFbB4FxVA6okLd9YfsipxGO1YsxVxdB1d2zQs3U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700732559; 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=MYG7EOawCsalqHQjO7r6fWUAmQwiesUHyef10i6e7jU=; b=iJ2k7ff1FyL8TXu9hZ8HH8wloajBIZGfO4kQkRN1Hqz3rW/UxcilSKagL/s12u6rcQ99YL 3Se5jUREKvaEsk4If2MfF+/Gm/SxIgRcpFDgBAkz3Iaz/XqrR5vhUUV44Kxa90XzN2KLsZ zD123IyNMJbZq6fBiJHXcLZg0+h3Oeo= 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-392-Klr3zEglOOaLiHxOmOEPeg-1; Thu, 23 Nov 2023 04:42:35 -0500 X-MC-Unique: Klr3zEglOOaLiHxOmOEPeg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 7FC823C0C10D; Thu, 23 Nov 2023 09:42:35 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 432381C060B5; Thu, 23 Nov 2023 09:42:35 +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 3AN9gW0B888789 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Nov 2023 10:42:33 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AN9gV5X888788; Thu, 23 Nov 2023 10:42:31 +0100 Date: Thu, 23 Nov 2023 10:42:31 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up -fnon-call-exceptions bit-field load lowering [PR112668] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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_H3, 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: 1783347369768172962 X-GMAIL-MSGID: 1783347369768172962 Hi! As the following testcase shows, there are some bugs in the -fnon-call-exceptions bit-field load lowering. In particular, there is a case where we want to emit a load early in the initialization (before m_init_gsi) and because that load might throw exception, need to split block after the load so that it has an EH edge. Now, across this splitting, we have m_init_gsi, save_gsi (something we put back into m_gsi afterwards) statement iterators and m_preheader_bb which is used to determine the pre-header edge of a loop (if any). As the testcase shows, both of these statement iterators and m_preheader_bb as well need adjustments if the block was split. If the stmt iterators refer to a statement, they need to be updated so that if the statement is in the bb after the split gsi_bb and gsi_seq is updated, otherwise they ought to be the start of the new (second) bb. Similarly, m_preheader_bb should be updated to the second bb if it was the first before. Other spots where we insert something before m_init_gsi don't split blocks in there and are fine. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-23 Jakub Jelinek PR middle-end/112668 * gimple-lower-bitint.cc (bitint_large_huge::handle_load): When splitting gsi_bb (m_init_gsi) basic block, update m_preheader_bb if needed, fix up update of m_init_gsi and update saved m_gsi as well if needed. * gcc.dg/bitint-40.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-11-14 10:52:16.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2023-11-22 14:34:17.327140002 +0100 @@ -1687,7 +1687,22 @@ 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_init_gsi = gsi_last_bb (e->dest); + if (!gsi_end_p (m_init_gsi)) + gsi_next (&m_init_gsi); + if (gsi_bb (save_gsi) == e->src) + { + if (gsi_end_p (save_gsi)) + { + save_gsi = gsi_last_bb (e->dest); + if (!gsi_end_p (save_gsi)) + gsi_next (&save_gsi); + } + else + save_gsi = gsi_for_stmt (gsi_stmt (save_gsi)); + } + if (m_preheader_bb == e->src) + m_preheader_bb = e->dest; } } m_gsi = save_gsi; --- gcc/testsuite/gcc.dg/bitint-40.c.jj 2023-11-22 13:47:12.380580107 +0100 +++ gcc/testsuite/gcc.dg/bitint-40.c 2023-11-22 14:35:50.225842768 +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