From patchwork Fri Jan 12 09:34:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1885931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LBlfliOu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TBGkP4ZGfz1yPm for ; Fri, 12 Jan 2024 20:41:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BC5F38582BE for ; Fri, 12 Jan 2024 09:40: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 0BCF73858D35 for ; Fri, 12 Jan 2024 09:39:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BCF73858D35 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 0BCF73858D35 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=1705052383; cv=none; b=r8G0buVT4Thq9R5B1zW11qa1x2blLn2pzTOI78E5sS/Mer8k2vv0L/4+osgp+cO34kEWr2cggImXrAJ/nxBegwlCMhV6bIWa4NImvVJ+QIOF314iKGotefek1zMkeUr47nnCQYFEdQnVxQnsEg9+ivGHU4WMlHM+Cc2gIM25Fto= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705052383; c=relaxed/simple; bh=NDufZvcst3KvJ04CBvADn8cT7zGuqqsoMhCSc/QvUGI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=xiPgdbocUTNU3CH2/jqguOlJgY9XDIQRjYluF/5Q/bC6kt5Tt89Us7rdj+zmwmo34vuqep/9YvpKpCedT905OJn2Snm4VMlxE3BcMCEYd9cAyFuDDjAN+Or6pcRqooVaoQN93zfrg3y1ya0K8XdU+K+MdphH0s6X0Ond4K30PAU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705052378; 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:resent-to:resent-from:resent-message-id; bh=hzOkEpWpA5uaNbfZgcsqMEZ0Ht9IYLwGeXSIi/AQYWM=; b=LBlfliOuAEjPm06ByBBdXyIFlBkN10WIj64Y25YqncArCTPSKWz0Ya29zloII0QRE1M4n1 LgMeEaSIq1CSWFkBc2bGMAAramDUYDX3M/D41NCNJWpe3F1MaDft7qAQiEg4lCm1Vquk1j 4ZSMuAwQGqdDyBSFYjDjuvQJeywF9zQ= 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-645-HgpHqyFqNAWR2dWDDbeMoA-1; Fri, 12 Jan 2024 04:39:32 -0500 X-MC-Unique: HgpHqyFqNAWR2dWDDbeMoA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 F211C185A781; Fri, 12 Jan 2024 09:39:31 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5F342166B31; Fri, 12 Jan 2024 09:39: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 40C9dTkG3307030 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 12 Jan 2024 10:39:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40C9dS8k3307029; Fri, 12 Jan 2024 10:39:28 +0100 Resent-From: Jakub Jelinek Resent-Date: Fri, 12 Jan 2024 10:39:28 +0100 Resent-Message-ID: Resent-To: Richard Biener , gcc-patches@gcc.gnu.org Date: Fri, 12 Jan 2024 10:34:04 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up handling of uninitialized large/huge _BitInt call arguments [PR113316] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The code to assign large/huge _BitInt SSA_NAMEs to partitions intentionally ignores uninitialized SSA_NAMEs: /* Also ignore uninitialized uses. */ if (SSA_NAME_IS_DEFAULT_DEF (s) && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s)))) continue; because there is no need to store them into memory, all we need is when trying to extract some limb from them use uninitialized SSA_NAME for the limb. The following testcase shows this is a problem for call arguments though, for those we need to create replacement SSA_NAMEs which are loaded from the underlying variable. For uninitialized SSA_NAMEs because we didn't create underlying variable for them var_to_partition doesn't work, the following patch handles it by just creating an uninitialized replacement SSA_NAME. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-12 Jakub Jelinek PR tree-optimization/113316 * gimple-lower-bitint.cc (bitint_large_huge::lower_call): Handle uninitialized large/huge _BitInt arguments to calls. * gcc.dg/bitint-67.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-01-11 11:46:49.147779946 +0100 +++ gcc/gimple-lower-bitint.cc 2024-01-11 13:52:46.106182653 +0100 @@ -5118,14 +5118,23 @@ bitint_large_huge::lower_call (tree obj, || TREE_CODE (TREE_TYPE (arg)) != BITINT_TYPE || bitint_precision_kind (TREE_TYPE (arg)) <= bitint_prec_middle) continue; - int p = var_to_partition (m_map, arg); - tree v = m_vars[p]; - gcc_assert (v != NULL_TREE); - if (!types_compatible_p (TREE_TYPE (arg), TREE_TYPE (v))) - v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg), v); - arg = make_ssa_name (TREE_TYPE (arg)); - gimple *g = gimple_build_assign (arg, v); - gsi_insert_before (&gsi, g, GSI_SAME_STMT); + if (SSA_NAME_IS_DEFAULT_DEF (arg) + && (!SSA_NAME_VAR (arg) || VAR_P (SSA_NAME_VAR (arg)))) + { + tree var = create_tmp_reg (TREE_TYPE (arg)); + arg = get_or_create_ssa_default_def (cfun, var); + } + else + { + int p = var_to_partition (m_map, arg); + tree v = m_vars[p]; + gcc_assert (v != NULL_TREE); + if (!types_compatible_p (TREE_TYPE (arg), TREE_TYPE (v))) + v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg), v); + arg = make_ssa_name (TREE_TYPE (arg)); + gimple *g = gimple_build_assign (arg, v); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + } gimple_call_set_arg (stmt, i, arg); if (m_preserved == NULL) m_preserved = BITMAP_ALLOC (NULL); --- gcc/testsuite/gcc.dg/bitint-67.c.jj 2024-01-11 13:54:14.561936065 +0100 +++ gcc/testsuite/gcc.dg/bitint-67.c 2024-01-11 13:55:09.474162196 +0100 @@ -0,0 +1,12 @@ +/* PR tree-optimization/113316 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=c23 -O2 -w" } */ + +void bar (_BitInt(535) y); + +void +foo (void) +{ + _BitInt(535) y; + bar (y); +}