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: 82744 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 C35C33858427 for ; Fri, 22 Dec 2023 08:17:51 +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+patchwork=sourceware.org@gcc.gnu.org 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