From patchwork Fri Nov 24 08:15:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 169275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp993774vqx; Fri, 24 Nov 2023 00:15:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnLDGvRdaVu9ub07Em/N9EuODDtTJ76iMsSa0bjJ7FbyH44nRGS0TdGO9tFCQr7F2S3PGC X-Received: by 2002:a05:620a:4092:b0:77d:77b7:d0e3 with SMTP id f18-20020a05620a409200b0077d77b7d0e3mr2218241qko.9.1700813754457; Fri, 24 Nov 2023 00:15:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700813754; cv=pass; d=google.com; s=arc-20160816; b=ghN9o34i7Cl0rhx6pvkHbw1xHdxmJ7SQcuItD+ZMzYZSq45eWyH7Gh6MzzQhagQX3r h4G8Nk7cX4XDT8Ey0RqwZbKSyfSc1+eARC3Hhr90mpF2DdbaoMxXkoBDDFKzWzwsjV6S 7WXnmdz5WspuSxlRTaiJxV/j+62m6hE9tMXcxKvJ0EhM09iKEEVfWiPFiC6zFHdgZnf6 9v8+6bFHuKju82AV/DKTfhjPGaB6JEhCD5oo/060yT496imi/Blm+R+2IgIBGjOHIfyA EDdtEqAUPGMu5D2qWHIgMGnfg8u89owX/yiHuzjS2X/PuhHmvSsnADlQG/z9RNZoJ1Vr RHjA== 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=NgVLuJ9cpJ3qtRmxtMZ1nUfIx8o0PG51gwELA0uDgoM=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=c15aDrkSIzVaDqqIjq5lwj7hRZjyZbx+OqU8G/zxkQu1EOozg6Mhk4nyuVP7da8KbI +j9xVq7Wp85HgzgXw+yUBfR4ZOU1eGQTEa1ZF6xq6d44UO3zgDqD8SzxKjq59fegsSsr pWU8SvMv3RQk16chSpbTx57SEMBiOO4cQMDn7qbROUtSl70dsiSEHlHi0meAoE6bxOYF fW7B8DgH/8DKW/5D079sziW3jt49XTxFTHn8HUVUtTsOUzhDb8C8tg8YycqjlWhAYRJB ER4+bzi2ItWb6mfoteZDfXHuqbtm5RUW1aNTthgo08puBxpTuMy9WxmkZRbnGqU6Fd9Z HpGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XJ+V30q1; 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 w17-20020a05620a445100b0077d57fbbc47si2790017qkp.678.2023.11.24.00.15.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:15:54 -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=XJ+V30q1; 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 2AC713858005 for ; Fri, 24 Nov 2023 08:15:54 +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 9371D3858D39 for ; Fri, 24 Nov 2023 08:15:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9371D3858D39 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 9371D3858D39 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=1700813724; cv=none; b=EZ+FebwVdYJWXFMs9QCo6zEeDcLDf4c3B5/PTSjmwRMMzIriMOJ7vihMDy9x0HFZ/8lNT2ulUO/h32OqFsOlL+hvLOYzsIEddWSZhN0velMJ0iGwAV5bbzHGB0+bj39HQpyLZiaWdjRvTuKlyYogVkVhJIixgEnSzbCAibUUpJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700813724; c=relaxed/simple; bh=yq+8xWBH4NMc0Ud1t9HO3bVHLd/TX8FiMc01H2hITrM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=vCx4Lpgkes9gGQjy3oYYh50fKnAjWcQz/ifEVGDQEAqH7BuMBID9sVa3O4LHB/8KvNZgX9F0ByJ5RzgzzRYuEq9Dnux1FFwvUX4R8bwnZo/Ij9B/N0v2h+GZUMXF8792qodL6Xuo8BUjrlg0uZRj4GaiAjtIbSXBnG+luEDTkVI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700813722; 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=NgVLuJ9cpJ3qtRmxtMZ1nUfIx8o0PG51gwELA0uDgoM=; b=XJ+V30q1QuJGvdHKUzkrTqFjRWEvcsmsDbj+UDQxbD7AYoFVIsDtqf1KyriIUMe/1cn3d/ ArSL3gAIAQrsJPgLU/GLkfJp67G+EJ78p9aikWNjMOz0/fdiWk/vFhRgQaGxf8VCVnamtn f+7OK29IvSfojcWnZNGFt+qpbn3ZYog= 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-450-gzhtXNjCP8ScmbK1nyaVgQ-1; Fri, 24 Nov 2023 03:15:18 -0500 X-MC-Unique: gzhtXNjCP8ScmbK1nyaVgQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 E579B3C027E1; Fri, 24 Nov 2023 08:15:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7CDD2026D4C; Fri, 24 Nov 2023 08:15:17 +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 3AO8FF6i3449204 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 09:15:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AO8FEs83449203; Fri, 24 Nov 2023 09:15:14 +0100 Date: Fri, 24 Nov 2023 09:15:14 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Lower FLOAT_EXPR from BITINT_TYPE INTEGER_CST [PR112679] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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: 1783432483835167795 X-GMAIL-MSGID: 1783432483835167795 Hi! The bitint lowering pass only does something if it sees BITINT_TYPE (medium, large, huge) SSA_NAMEs. In the past I've already ran into one special case where the above doesn't work well, if there is a store of medium/large/huge BITINT_TYPE INTEGER_CST into memory, there might not be any BITINT_TYPE SSA_NAMEs in the function, yet we need to lower. This has been solved by also checking for SSA_NAME_IS_VIRTUAL_OPERAND if at the vdef there isn't such a store (the whole intent is make the pass as cheap as possible in the currently very likely case that the IL doesn't have any BITINT_TYPEs at all). And the following testcase shows a similar problem. With -frounding-math we don't fold some of FLOAT_EXPRs with INTEGER_CST operands, and if those INTEGER_CSTs are medium/large/huge BITINT_TYPEs, we need to either cast the INTEGER_CST to corresponding INTEGER_TYPE (for medium) or lower to internal fn call which is later turned into libgcc call (for large/huge). The following patch does that, but of course admittedly this discovery of stores and FLOAT_EXPRs means we already look through quite a few SSA_NAME_DEF_STMTs even when BITINT_TYPEs never appear. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-23 Jakub Jelinek PR middle-end/112679 * gimple-lower-bitint.cc (gimple_lower_bitint): Also stop first loop on floating point SSA_NAME set in FLOAT_EXPR assignment from BITINT_TYPE INTEGER_CST. Set has_large_huge for those if that BITINT_TYPE is large or huge. Set kind to such FLOAT_EXPR assignment rhs1 BITINT_TYPE's kind. * gcc.dg/bitint-42.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-11-23 14:30:02.830662509 +0100 +++ gcc/gimple-lower-bitint.cc 2023-11-23 16:17:59.217298778 +0100 @@ -5635,6 +5635,21 @@ gimple_lower_bitint (void) break; } } + /* Similarly, e.g. with -frounding-math casts from _BitInt INTEGER_CSTs + to floating point types need to be rewritten. */ + else if (SCALAR_FLOAT_TYPE_P (type)) + { + gimple *g = SSA_NAME_DEF_STMT (s); + if (is_gimple_assign (g) && gimple_assign_rhs_code (g) == FLOAT_EXPR) + { + tree t = gimple_assign_rhs1 (g); + if (TREE_CODE (t) == INTEGER_CST + && TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (t)) + != bitint_prec_small)) + break; + } + } } if (i == num_ssa_names) return 0; @@ -5855,6 +5870,21 @@ gimple_lower_bitint (void) has_large_huge = true; } } + /* Similarly, e.g. with -frounding-math casts from _BitInt INTEGER_CSTs + to floating point types need to be rewritten. */ + else if (SCALAR_FLOAT_TYPE_P (type)) + { + gimple *g = SSA_NAME_DEF_STMT (s); + if (is_gimple_assign (g) && gimple_assign_rhs_code (g) == FLOAT_EXPR) + { + tree t = gimple_assign_rhs1 (g); + if (TREE_CODE (t) == INTEGER_CST + && TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (t)) + >= bitint_prec_large)) + has_large_huge = true; + } + } } for (i = first_large_huge; i < num_ssa_names; ++i) { @@ -6182,6 +6212,19 @@ gimple_lower_bitint (void) { bitint_prec_kind this_kind = bitint_precision_kind (TREE_TYPE (t)); + if (this_kind > kind) + kind = this_kind; + } + } + if (is_gimple_assign (stmt) + && gimple_assign_rhs_code (stmt) == FLOAT_EXPR) + { + t = gimple_assign_rhs1 (stmt); + if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE + && TREE_CODE (t) == INTEGER_CST) + { + bitint_prec_kind this_kind + = bitint_precision_kind (TREE_TYPE (t)); if (this_kind > kind) kind = this_kind; } --- gcc/testsuite/gcc.dg/bitint-42.c.jj 2023-11-23 16:50:52.392502318 +0100 +++ gcc/testsuite/gcc.dg/bitint-42.c 2023-11-23 16:42:08.559881704 +0100 @@ -0,0 +1,9 @@ +/* PR middle-end/112679 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-frounding-math" } */ + +float +foo (void) +{ + return 0x353eab28b46b03ea99b84f9736cd8dbe5e986915a0383c3cb381c0da41e31b3621c75fd53262bfcb1b0e6251dbf00f3988784e29b08b65640c263e4d0959832a20e2ff5245be1e60uwb; +}