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: 187628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp62334dyc; Fri, 12 Jan 2024 01:41:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+7Q81/CF46ZnVxsAetYHx2cDE2f9G22GHY9QLNcTNZv1H4Yhhsx2bOf8Ow7QzKkeA45I5 X-Received: by 2002:a05:6214:19c9:b0:681:aa8:41af with SMTP id j9-20020a05621419c900b006810aa841afmr704857qvc.97.1705052491193; Fri, 12 Jan 2024 01:41:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705052491; cv=pass; d=google.com; s=arc-20160816; b=kY1AM1b7zdVzlYonRfQYkdBxYKbeLuxwAMjkNV7xqF0A/dC27IFk8oe2zxgCB0y8Pa Vnp9HkcPXhAwJUWb8XMil3NDPp3BOuWIHuDWmkZnq3i7DH/bqc/q8l4Ho4BEm9Hqpxtc vzXHxer2h/LK52w1vtDm/qcn4aKiWu1QaEOuwsdCTIWEXWxexOmPqxqyNevjiw+gNI8g q+rvTy11OUwKYI8jmnilHnsBYeBj+8BvX70k+SI8146Sc+Rzai4SvPouD+s4uYuLlyJh +fONJcx78ykJAiNtGWL1cGOxwoL/+85mIe1Thfrrcm+BHEKGB2UHAnBh3vnyZ+TcQbs4 wgqw== 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:resent-to :resent-message-id:resent-date:resent-from:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=hzOkEpWpA5uaNbfZgcsqMEZ0Ht9IYLwGeXSIi/AQYWM=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=TNs870RjXal5JAXFk4oX6gwBUNYZOfXlXWdzCUzIsHEVD5maQF0kPeATnu+4oLgaFl 4Y8TeNlhIqKg2FDNxOkJzvmdbJmTSspQdcCS/OiRF5pheez9FIdypL2f7sYavs2C+J9k PRkO9ofcqwmnYnsR1O6dX/NY7eFTj3Pgb/7q5tlw9puKL4obeGK77gxI4hSxOcuhN54P yXEfk/aBTK59twy+zW625NMYyYrVJDwYneMZRh9uoYdLA+MFyY8MNASzjmuzhH9pwzlU tWFApoUecU+lN6MB7dywC5h7XZ+ERw/tejtFr6IoINswBmkp2aKDE7W93hYquHw3Dfqw lUBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LBlfliOu; 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 y4-20020a0c8ec4000000b0068124c6d6cfsi2481329qvb.75.2024.01.12.01.41.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 01:41:31 -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=LBlfliOu; 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 DF70D3858015 for ; Fri, 12 Jan 2024 09:41:30 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787877121051471780 X-GMAIL-MSGID: 1787877121051471780 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); +}