From patchwork Thu Dec 21 07:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 182017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp231186dyi; Wed, 20 Dec 2023 23:00:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgQHQX+BSKZI7dYLt/YfNWzWHNXLv5+yipXh70KoSPxtqrHc1S8q2sHZ/wDAoufUvYZ5tr X-Received: by 2002:ac8:7d8f:0:b0:427:7d71:daee with SMTP id c15-20020ac87d8f000000b004277d71daeemr287263qtd.36.1703142038205; Wed, 20 Dec 2023 23:00:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703142038; cv=pass; d=google.com; s=arc-20160816; b=hIL3V90igme6rLXgeyUbIfxqOYsIXUJCe5223dPnOtHL9KnQKin0e1t16nY/fyyjKb TONI9kzSitq2GoMZt7d5tIw/uO9+bg5rs5a9Cjg8n5g0lr78YwlH/7god22NUP+LQoCL ym5AVedVJ92XUGXiEJQ7W3p6r72kYYjbzdaseF6N/201RQJ0pUvAO0rBiEGeIOERvklk l5ZZw27QsNxrM7q9Gf6L2xuGSQuj6jFc7AIEAw1igXXXBPZ8Nf4iz7t0TKpBsbwQVxvc 6eqYwWy66MFW60biRiGhpveXsJjq+gyaipZ3o9vGmHoYEJ2pKeuadk3SUyAo3XP+hVYj rihw== 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=jlQeTDv9tjShRnRJY34dsEOtX1yrjE0jTnK89FxF1yY=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=OUTTwhz5KDmyVvepmd4wffPOjET+wkf8qxqzxfR6yLfbunf6ilEGmfRVdFYz94io0h euBXzsconQ7fLTxjGYh+v71vTA+cLYilejMEXhR/GafZXWLO7uHOPa50sGXcBsz2R0hF AA8XEaBABOhT7OuBCtMk4pnpbeasNRlcRRqkZQTyGxTpUeTRa6ikhdajjYMTd9VUo2qo MHJDusDUejxjOyMFiKNUpHkXfxxufgW86fE7DuBLaprbIU5kT8hWEozDVXQUzRWhQj7v B/H/isDNJci4K7LzJTzGpXiypNhJsf56o9GkPkqz1Q3w/732jNV7kVKBdTFdIp3XRy+u lxLQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dfC827za; 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 w18-20020ac87e92000000b0042613fe1d38si1474230qtj.588.2023.12.20.23.00.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 23:00:38 -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=dfC827za; 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 E80273853328 for ; Thu, 21 Dec 2023 07:00:37 +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 3A3283858407 for ; Thu, 21 Dec 2023 07:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A3283858407 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 3A3283858407 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=1703142014; cv=none; b=X0gxnTGdSp8e9f74yHPjESdSfom5uc2JGOaWIvOS8ZUhzcPDMh3jIlBFQ4Ue6Mr952HZzXE9c2S2xEBWecozuxSFVEjJLUVfyJfEB10uViLauW88zp4mkc8EGI5bX5pHb4UJJFBUkkKO1AOy7mShB2we8C8zR7nUX6MWwX7ZBVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703142014; c=relaxed/simple; bh=vCLQXmqectiR9d2RfbE1e343xfehcVS/eC3J7LwPsag=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=o8kE7QnzQJXQFWrp8bdl42mi98ZwpNbrP8ZIJsTODfnLVFxt6CSRmtNiqzB1TA/e5A+jHbSAeSHvlcRRUkege2KlO09mCBXRU8TlbnKbx4UnifCyWTVWny/9ykBwxEleH25xhfJ/TT+5r6euwW2viQR0L00PTsySHRxXKFEKLY8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703142012; 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=jlQeTDv9tjShRnRJY34dsEOtX1yrjE0jTnK89FxF1yY=; b=dfC827zaqjH4LuIDS1+9o1pFT1V+1nGtMfRf3FkfCEVg59JygTeAGxs+I1g1aQ65Sg8V9B P6IA8CMXDsxx8nMGQySQtB6diyh+lEYMm+OPMmI/3GRd3gzv/SFWPYqy8ugMCt+Jhyir1G qTM4O8tPMeEvwebFMy8VTS/1kIwwyn8= 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-41-Z9ltJHgsMTWsDuxaBn2F8g-1; Thu, 21 Dec 2023 02:00:09 -0500 X-MC-Unique: Z9ltJHgsMTWsDuxaBn2F8g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 99B341019C91; Thu, 21 Dec 2023 07:00:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59D79112131D; Thu, 21 Dec 2023 07:00:09 +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 3BL7064J1608183 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 21 Dec 2023 08:00:07 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BL706Ip1608182; Thu, 21 Dec 2023 08:00:06 +0100 Date: Thu, 21 Dec 2023 08:00:05 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Avoid nested casts in muldiv/float operands [PR112941] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.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: 1785873866143435119 X-GMAIL-MSGID: 1785873866143435119 Hi! Multiplication/division/modulo/float operands are handled by libgcc calls and so need to be passed as array of limbs with precision argument, using handle_operand_addr. That code can't deal with more than one cast, so the following patch avoids merging those cases. .MUL_OVERFLOW calls use the same code, but we don't actually try to merge the operands in that case already. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-21 Jakub Jelinek PR tree-optimization/112941 * gimple-lower-bitint.cc (gimple_lower_bitint): Disallow merging a cast with multiplication, division or conversion to floating point if rhs1 of the cast is result of another single use cast in the same bb. * gcc.dg/bitint-56.c: New test. * gcc.dg/bitint-57.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-12-20 11:32:45.898425928 +0100 +++ gcc/gimple-lower-bitint.cc 2023-12-20 12:47:00.168727583 +0100 @@ -6060,6 +6060,26 @@ gimple_lower_bitint (void) || (bitint_precision_kind (TREE_TYPE (rhs1)) < bitint_prec_large)) continue; + if (is_gimple_assign (use_stmt)) + switch (gimple_assign_rhs_code (use_stmt)) + { + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + case FLOAT_EXPR: + /* Uses which use handle_operand_addr can't + deal with nested casts. */ + if (TREE_CODE (rhs1) == SSA_NAME + && gimple_assign_cast_p + (SSA_NAME_DEF_STMT (rhs1)) + && has_single_use (rhs1) + && (gimple_bb (SSA_NAME_DEF_STMT (rhs1)) + == gimple_bb (SSA_NAME_DEF_STMT (s)))) + goto force_name; + break; + default: + break; + } if ((TYPE_PRECISION (TREE_TYPE (rhs1)) >= TYPE_PRECISION (TREE_TYPE (s))) && mergeable_op (use_stmt)) @@ -6154,6 +6174,7 @@ gimple_lower_bitint (void) && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s)))) continue; + force_name: if (!large_huge.m_names) large_huge.m_names = BITMAP_ALLOC (NULL); bitmap_set_bit (large_huge.m_names, SSA_NAME_VERSION (s)); --- gcc/testsuite/gcc.dg/bitint-56.c.jj 2023-12-20 12:41:28.208398219 +0100 +++ gcc/testsuite/gcc.dg/bitint-56.c 2023-12-20 12:38:08.548204489 +0100 @@ -0,0 +1,129 @@ +/* PR tree-optimization/112941 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +#if __BITINT_MAXWIDTH__ >= 4096 +void +f1 (_BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] *= (unsigned _BitInt(2048)) r; + p[1] *= (unsigned _BitInt(2048)) s; + p[2] *= (unsigned _BitInt(2048)) t; + p[3] *= (unsigned _BitInt(2048)) u; +} + +void +f2 (_BitInt(4094) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] /= (unsigned _BitInt(2048)) r; + p[1] /= (unsigned _BitInt(2048)) s; + p[2] /= (unsigned _BitInt(2048)) t; + p[3] /= (unsigned _BitInt(2048)) u; +} + +void +f3 (_BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] *= (unsigned _BitInt(2110)) r; + p[1] *= (unsigned _BitInt(2110)) s; + p[2] *= (unsigned _BitInt(2110)) t; + p[3] *= (unsigned _BitInt(2110)) u; +} + +void +f4 (_BitInt(4094) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] /= (unsigned _BitInt(2110)) r; + p[1] /= (unsigned _BitInt(2110)) s; + p[2] /= (unsigned _BitInt(2110)) t; + p[3] /= (unsigned _BitInt(2110)) u; +} + +void +f5 (unsigned _BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] *= (unsigned _BitInt(2048)) r; + p[1] *= (unsigned _BitInt(2048)) s; + p[2] *= (unsigned _BitInt(2048)) t; + p[3] *= (unsigned _BitInt(2048)) u; +} + +void +f6 (unsigned _BitInt(4094) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] /= (unsigned _BitInt(2048)) r; + p[1] /= (unsigned _BitInt(2048)) s; + p[2] /= (unsigned _BitInt(2048)) t; + p[3] /= (unsigned _BitInt(2048)) u; +} + +void +f7 (unsigned _BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] *= (unsigned _BitInt(2110)) r; + p[1] *= (unsigned _BitInt(2110)) s; + p[2] *= (unsigned _BitInt(2110)) t; + p[3] *= (unsigned _BitInt(2110)) u; +} + +void +f8 (unsigned _BitInt(4094) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u) +{ + p[0] /= (unsigned _BitInt(2110)) r; + p[1] /= (unsigned _BitInt(2110)) s; + p[2] /= (unsigned _BitInt(2110)) t; + p[3] /= (unsigned _BitInt(2110)) u; +} + +#if __SIZEOF_INT128__ +void +f9 (_BitInt(4096) *p, __int128 r) +{ + p[0] *= (unsigned _BitInt(2048)) r; +} + +void +f10 (_BitInt(4094) *p, __int128 r) +{ + p[0] /= (unsigned _BitInt(2048)) r; +} + +void +f11 (_BitInt(4096) *p, __int128 r) +{ + p[0] *= (unsigned _BitInt(2110)) r; +} + +void +f12 (_BitInt(4094) *p, __int128 r) +{ + p[0] /= (unsigned _BitInt(2110)) r; +} + +void +f13 (unsigned _BitInt(4096) *p, __int128 r) +{ + p[0] *= (unsigned _BitInt(2048)) r; +} + +void +f14 (unsigned _BitInt(4094) *p, __int128 r) +{ + p[0] /= (unsigned _BitInt(2048)) r; +} + +void +f15 (unsigned _BitInt(4096) *p, __int128 r) +{ + p[0] *= (unsigned _BitInt(2110)) r; +} + +void +f16 (unsigned _BitInt(4094) *p, __int128 r) +{ + p[0] /= (unsigned _BitInt(2110)) r; +} +#endif +#else +int i; +#endif --- gcc/testsuite/gcc.dg/bitint-57.c.jj 2023-12-20 12:42:12.691772991 +0100 +++ gcc/testsuite/gcc.dg/bitint-57.c 2023-12-20 12:42:49.900250015 +0100 @@ -0,0 +1,21 @@ +/* PR tree-optimization/112941 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O1 -fno-tree-forwprop" } */ + +#if __BITINT_MAXWIDTH__ >= 6384 +unsigned _BitInt(2049) +foo (unsigned _BitInt(6384) x, _BitInt(8) y) +{ + unsigned _BitInt(6384) z = y; + return x * z; +} + +_BitInt(2049) +bar (unsigned _BitInt(6384) x, _BitInt(1023) y) +{ + unsigned _BitInt(6384) z = y; + return x * z; +} +#else +int i; +#endif