From patchwork Fri Dec 22 08:17:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 182588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp915897dyi; Fri, 22 Dec 2023 00:18:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvN1Jnyc6Kydqx6WR7G7DZkjP9+78mCEQsCVMl60N7Izg1df/ypAQx8D+IJQyESRFp3Bcr X-Received: by 2002:a05:6870:6490:b0:204:11b1:9aef with SMTP id cz16-20020a056870649000b0020411b19aefmr1050046oab.96.1703233081404; Fri, 22 Dec 2023 00:18:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703233081; cv=pass; d=google.com; s=arc-20160816; b=T3qJylYbv2/e/lOd/Ur7yrPaeFWXOv4BJI1+br/euY12TJhR42gI4PcLfF2tHAmD4F OB1Pqu7kCWJEGmiE+HcAI30hI7lvMcL0yVIQkXp4ld7ok35hI4pzgOCGEmIapj6LkNAj P7yzaILBq0lp0REzijzMSU63BzyvS1lPUEsv26k/eiX0hw+0fG3eNv6WuHOt/yqYXbSn YUziq9XydvoVddqgdgdW9/cXGCP4dBeFC2TkZI8QRQ5hOt7wA0PVlbrO4IeB+ZxFu8vT KG8qljY6iJvcysEWV2cgJS0mqzioXWRSdpKYhkhQKdLpcXCM8txJI6srXghcU/DyZ3LM r3bg== 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=4VwFLo+d74iLRoLu00Rt41dI90g/Gnvw81eNFdQzQuk=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=qO2xI7NMi0lwFch6k1O8EbjFEJA+36uwoRD4SJSOdRxvNzvKd8454Gkw1QXR/WTYdy saCsoQe2e/KTtPTJPXtIUxFdLI1UcwFInhMMxXtwEir7LeZfTpiZmv0uJ18TXnrwPYz4 V2W9kBenKHovOc708NcTF2C/Vp5i3Xmv/Cl36Glaa2YmsTt891tic1ecshIVJYH3Fbg8 gYvLuhbuX0meFZOm12u4rtra2XfQtgQ6/RBPifhetAh0i+il5JEpxmPACTxYrODscI+O 54vzP6mZ72lO8yXBfc/nb6S0oknhoaCZ10/Y33JXhS955koUorp/ETKBz2miWSaJQp3O H5mQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="FElPeu/E"; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bl15-20020a05620a1a8f00b007810c3ee539si4181282qkb.310.2023.12.22.00.18.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 00:18: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="FElPeu/E"; 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 224E33858432 for ; Fri, 22 Dec 2023 08:18: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 681C73858D33 for ; Fri, 22 Dec 2023 08:17:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 681C73858D33 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 681C73858D33 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=1703233054; cv=none; b=rgtpRI0ASRQG4dxOYppEMCJHxsAjZWp4lV6wd1Lpz5Y1k16C68T1BpgE86OJr9mUqJFqLXEbA+Au9SrBJj4mAq1tTBBkKy4GnCTmOjDnDvO8NpWcE4VY0Bmj+JrQsfTBzDsrrhfKYHS7R+oHBcoSSYWGOGYV1O9Tlphmr3yr/50= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703233054; c=relaxed/simple; bh=Y/GMr6tOf1DRzfPMCgpxw2gctBvWq8ZWiwN4S2a15kc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=tS3bTS8xaW/EH9CbDNP1D614RQgi2aat4LN5PEyGyQ6ft42+YU3fsrJLelKKiIiow4omNYATJEMApmvJqZN203s/UzF1qDeH/6+g4NrcKgCOnxaMXtf7uimXheEL8oDS6lho2c8LC3t9jYJI/QwmZFFCK0XZtqahcPyQlu0AS6g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703233050; 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=4VwFLo+d74iLRoLu00Rt41dI90g/Gnvw81eNFdQzQuk=; b=FElPeu/Ejv9aXEohCrPUYyi7mMYsv58/miNOXIWcnPwVOv+9OQkyZ/0HBztPoyo9RnlF/7 7tgicWzbZuzg5xRgq5jwra1fD/P22mXt5+kUBQCZWTSyxQUzVh3MkXbNO+5JoS1NMniJFp 7A7x1CK4CP83k2jB7sBKQAtxsn3X1wY= 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-132-XE9a17iHP42crtvxBtBoUQ-1; Fri, 22 Dec 2023 03:17:26 -0500 X-MC-Unique: XE9a17iHP42crtvxBtBoUQ-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 3C7C028B7402; Fri, 22 Dec 2023 08:17:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 007701C060AF; Fri, 22 Dec 2023 08:17:25 +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 3BM8HNOQ241241 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Dec 2023 09:17:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BM8HMgs241240; Fri, 22 Dec 2023 09:17:22 +0100 Date: Fri, 22 Dec 2023 09:17:22 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Handle unreleased SSA_NAMEs from earlier passes gracefully [PR113102] 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: 1785969331722489914 X-GMAIL-MSGID: 1785969331722489914 Hi! On the following testcase earlier passes leave around an unreleased SSA_NAME - non-GIMPLE_NOP SSA_NAME_DEF_STMT which isn't in any bb. The following patch makes bitint lowering resistent against those, the first hunk is where we'd for certain kinds of stmts try to ammend them and the latter is where we'd otherwise try to remove them, neither of which works. The other loops over all SSA_NAMEs either already also check gimple_bb (SSA_NAME_DEF_STMT (s)) or it doesn't matter that much if we process it or not (worst case it means e.g. the pass wouldn't return early even when it otherwise could). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-22 Jakub Jelinek PR tree-optimization/113102 * gimple-lower-bitint.cc (gimple_lower_bitint): Handle unreleased large/huge _BitInt SSA_NAMEs. * gcc.dg/bitint-59.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-12-21 13:28:56.953120687 +0100 +++ gcc/gimple-lower-bitint.cc 2023-12-21 14:08:00.199704511 +0100 @@ -5827,7 +5827,7 @@ gimple_lower_bitint (void) tree_code rhs_code; /* Unoptimize certain constructs to simpler alternatives to avoid having to lower all of them. */ - if (is_gimple_assign (stmt)) + if (is_gimple_assign (stmt) && gimple_bb (stmt)) switch (rhs_code = gimple_assign_rhs_code (stmt)) { default: @@ -6690,6 +6690,11 @@ gimple_lower_bitint (void) release_ssa_name (s); continue; } + if (gimple_bb (g) == NULL) + { + release_ssa_name (s); + continue; + } if (gimple_code (g) != GIMPLE_ASM) { gimple_stmt_iterator gsi = gsi_for_stmt (g); --- gcc/testsuite/gcc.dg/bitint-59.c.jj 2023-12-21 14:12:01.860350727 +0100 +++ gcc/testsuite/gcc.dg/bitint-59.c 2023-12-21 14:11:54.766449179 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/113102 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +unsigned x; + +#if __BITINT_MAXWIDTH__ >= 191 +void +foo (void) +{ + unsigned _BitInt(191) b = x; + ~(b >> x) % 3; +} +#endif