From patchwork Sat Feb 24 07:39:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 205784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1032768dyb; Fri, 23 Feb 2024 23:40:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUC/TI116vC0IdwBy47VukbbrS3awtzSrHgTNpLz0J1kcegvF5KQiuqfFrqWp555G5fHHYwXIIOWpOOyNiAi9vsuflFVQ== X-Google-Smtp-Source: AGHT+IFJCHIs7LOJvoKaTIi+RCd8LdvZqF0USv+BpH4yg1ZYKQSPx298Tu1LdtloJ4R4tJf2N14g X-Received: by 2002:ac8:7e89:0:b0:42e:5a82:d448 with SMTP id w9-20020ac87e89000000b0042e5a82d448mr1795884qtj.25.1708760433409; Fri, 23 Feb 2024 23:40:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708760433; cv=pass; d=google.com; s=arc-20160816; b=rdKFZ//T5+jh4yyUjYQdPInirTb5KDTtlUAT3D7zdP6+ioTCA81902z4UPurGS367Z MWV+47DqG7VdqE9TgDeVADBnEylO72n1jpnGGZojy5UaHkG2i3EKMqP6qtnOip5pycwW QvWgyf2F7NCTakqwkjqW7KPSGWAt6mbB+oM3SqnmdrhziRNIUTSqAjMLxnRW5vFUOhXs bBAX7WyXE/yz7ZCi1FtYWuir3ZI3zjipopaDQpdimWgm91uI9McWr7OBQQITyS4Owdn/ UtuI4Cx1YVC5j7uSUImYxK3YkmK8Hx+vbSBc1UdWc8mgCavdDZomzMmuVT0DJyv4NTJs rkag== 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=X2bHnAvHbhzCspUqLOz86ExlAYySzLqlTgKeiVuQUog=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=PSSljWMahxoKtY13Hp3fW9ByY9hHdqup+wsa4S+XNNrnj4e512TfYdU5NR42VTy4T6 d4bmY/uJB8kS9PgMXbHy1cwUCUKSX3GSVK+sELVUyyvsfN9+6AbTmy2nH7UYSKMV/clA AAdf6ItTIHB7azIU4ODshr/xseBu5UwaqIR4UI+qYenDmmE1NVvAR5VyMFayl2J1KsBj PklUrQcXYNHwNbICH10MUc9kf7ZWFeepEOxtAE92tCphQlo1cSousoJkWufiTYigWSrl TFfosOTsJ5/joy9llukiPGE8A4gVZpG3Tr3HINuhccssLlRhiaYzVoK6NSSlmlkHVVum e2rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TP45Mb83; 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 i20-20020ac85c14000000b0042bf29af871si663814qti.62.2024.02.23.23.40.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 23:40:33 -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=TP45Mb83; 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 0ABEB385829B for ; Sat, 24 Feb 2024 07:40:33 +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 39102385841A for ; Sat, 24 Feb 2024 07:39:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39102385841A 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 39102385841A 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=1708760388; cv=none; b=vJ+Himcv85g9M4tJj3nyYPnVjulnIMjMO5yswnyBjzcklyQH++ZsgSE2kVexyfw6oDJS+//6bVZhpKjE95fx7tmKtL3UVePUtmt1TnQISJduqUswPuWpN0KU9ggJAQR4/ndhAHUKhgHv8Cn6XnuXwFf5Jj9TOWImds/lrKEWKZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708760388; c=relaxed/simple; bh=tirGXwhqxwHe3egurim9yxn28QdvbGKXWVJD4VWu+Io=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=x9347oC4Kk6VYcJSBWXl4EHJxYRbFFTQU100Kpd3YYdPHhsT6zStmt+8hu7v48++k4Lhk59XODSTeQBeltqVFL2cz0eCLhtcXPmcC0NKatu5eyGcT3dXVU5W3kkxrX6Wl+kifTaC5jDPD+Ge0pxGaLusPZAG9DsuES5JH1MoT/w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708760385; 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=X2bHnAvHbhzCspUqLOz86ExlAYySzLqlTgKeiVuQUog=; b=TP45Mb83aVQqL/GZTObfjyDMmio+5XwX6ZilkiXNK/ITZpt3N5pVmXG3hMZNDLUfPcl1td 9wYm9dmE8tD14TyWAl6liiZH+VSGTfSA3sAU583TTMKFINoj/PDM9ZYMeAE5qdKawNzaPt UKfEBDZnJaemig99OvzGoJdbj6d2iIY= 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-694-ApcPdQkzMbyfqHH1Zz3MNQ-1; Sat, 24 Feb 2024 02:39:42 -0500 X-MC-Unique: ApcPdQkzMbyfqHH1Zz3MNQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 AB78C3C0F1B5; Sat, 24 Feb 2024 07:39:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5ABCE40C94A7; Sat, 24 Feb 2024 07:39:41 +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 41O7dcLQ3980069 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 24 Feb 2024 08:39:39 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41O7dXmV3980068; Sat, 24 Feb 2024 08:39:33 +0100 Date: Sat, 24 Feb 2024 08:39:32 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Handle VIEW_CONVERT_EXPRs between large/huge BITINT_TYPEs and VECTOR/COMPLEX_TYPE etc. [PR114073] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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_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: 1791765180399523153 X-GMAIL-MSGID: 1791765180399523153 Hi! The following patch implements support for VIEW_CONVERT_EXPRs from/to large/huge _BitInt to/from vector or complex types or anything else but integral/pointer types which doesn't need to live in memory. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-24 Jakub Jelinek PR middle-end/114073 * gimple-lower-bitint.cc (bitint_large_huge::lower_stmt): Handle VIEW_CONVERT_EXPRs between large/huge _BitInt and non-integer/pointer types like vector or complex types. (gimple_lower_bitint): Don't merge VIEW_CONVERT_EXPRs to non-integral types. Fix up VIEW_CONVERT_EXPR handling. Allow merging VIEW_CONVERT_EXPR from non-integral/pointer types with a store. * gcc.dg/bitint-93.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-02-23 11:36:06.977015730 +0100 +++ gcc/gimple-lower-bitint.cc 2024-02-23 18:21:09.282751377 +0100 @@ -5305,27 +5305,21 @@ bitint_large_huge::lower_stmt (gimple *s else if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || POINTER_TYPE_P (TREE_TYPE (lhs)))) + || POINTER_TYPE_P (TREE_TYPE (lhs)) + || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)) { final_cast_p = true; - if (TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE - && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE + if (((TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE + && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE) + || (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + && !POINTER_TYPE_P (TREE_TYPE (lhs)))) && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR) { /* Handle VIEW_CONVERT_EXPRs to not generally supported huge INTEGER_TYPEs like uint256_t or uint512_t. These are usually emitted from memcpy folding and backends - support moves with them but that is usually it. */ - if (TREE_CODE (rhs1) == INTEGER_CST) - { - rhs1 = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), - rhs1); - gcc_assert (rhs1 && TREE_CODE (rhs1) == INTEGER_CST); - gimple_assign_set_rhs1 (stmt, rhs1); - gimple_assign_set_rhs_code (stmt, INTEGER_CST); - update_stmt (stmt); - return; - } + support moves with them but that is usually it. + Similarly handle VCEs to vector/complex types etc. */ gcc_assert (TREE_CODE (rhs1) == SSA_NAME); if (SSA_NAME_IS_DEFAULT_DEF (rhs1) && (!SSA_NAME_VAR (rhs1) || VAR_P (SSA_NAME_VAR (rhs1)))) @@ -5376,6 +5370,18 @@ bitint_large_huge::lower_stmt (gimple *s } } } + else if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large + && !INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && !POINTER_TYPE_P (TREE_TYPE (rhs1)) + && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + lhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs1), m_vars[part]); + insert_before (gimple_build_assign (lhs, rhs1)); + return; + } } if (gimple_store_p (stmt)) { @@ -5411,6 +5417,28 @@ bitint_large_huge::lower_stmt (gimple *s case IMAGPART_EXPR: lower_cplxpart_stmt (lhs, g); goto handled; + case VIEW_CONVERT_EXPR: + { + tree rhs1 = gimple_assign_rhs1 (g); + rhs1 = TREE_OPERAND (rhs1, 0); + if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && !POINTER_TYPE_P (TREE_TYPE (rhs1))) + { + tree ltype = TREE_TYPE (rhs1); + addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (lhs)); + ltype + = build_qualified_type (ltype, + TYPE_QUALS (TREE_TYPE (lhs)) + | ENCODE_QUAL_ADDR_SPACE (as)); + lhs = build1 (VIEW_CONVERT_EXPR, ltype, lhs); + gimple_assign_set_lhs (stmt, lhs); + gimple_assign_set_rhs1 (stmt, rhs1); + gimple_assign_set_rhs_code (stmt, TREE_CODE (rhs1)); + update_stmt (stmt); + return; + } + } + break; default: break; } @@ -6235,6 +6263,14 @@ gimple_lower_bitint (void) if (gimple_assign_cast_p (SSA_NAME_DEF_STMT (s))) { tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)); + if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR) + { + rhs1 = TREE_OPERAND (rhs1, 0); + if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && !POINTER_TYPE_P (TREE_TYPE (rhs1)) + && gimple_store_p (use_stmt)) + continue; + } if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) && ((is_gimple_assign (use_stmt) && (gimple_assign_rhs_code (use_stmt) @@ -6279,11 +6315,15 @@ gimple_lower_bitint (void) goto force_name; break; case VIEW_CONVERT_EXPR: - /* Don't merge with VIEW_CONVERT_EXPRs to - huge INTEGER_TYPEs used sometimes in memcpy - expansion. */ { tree lhs = gimple_assign_lhs (use_stmt); + /* Don't merge with VIEW_CONVERT_EXPRs to + non-integral types. */ + if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + goto force_name; + /* Don't merge with VIEW_CONVERT_EXPRs to + huge INTEGER_TYPEs used sometimes in memcpy + expansion. */ if (TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE && (TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)) --- gcc/testsuite/gcc.dg/bitint-93.c.jj 2024-02-23 17:28:44.761989660 +0100 +++ gcc/testsuite/gcc.dg/bitint-93.c 2024-02-23 17:28:33.092149911 +0100 @@ -0,0 +1,253 @@ +/* PR middle-end/114073 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -Wno-psabi" } */ +/* { dg-additional-options "-mavx512f" { target i?86-*-* x86_64-*-* } } */ + +typedef int V __attribute__((vector_size (sizeof (_BitInt(256))))); +typedef int W __attribute__((vector_size (sizeof (_BitInt(512))))); + +#if __BITINT_MAXWIDTH__ >= 256 && defined (__SIZEOF_INT128__) +_Complex __int128 +f1 (_BitInt(256) x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.x = x; + return u.y; +} + +_Complex __int128 +f2 (_BitInt(254) x) +{ + union U { _BitInt(254) x; _Complex __int128 y; } u; + u.x = x; + return u.y; +} + +_BitInt(256) +f3 (_Complex __int128 x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.y = x; + return u.x; +} + +_BitInt(252) +f4 (_Complex __int128 x) +{ + union U { _BitInt(252) x; _Complex __int128 y; } u; + u.y = x; + return u.x; +} + +_Complex __int128 +f5 (_BitInt(256) x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.x = x + 1; + return u.y; +} + +_Complex __int128 +f6 (_BitInt(254) x) +{ + union U { _BitInt(254) x; _Complex __int128 y; } u; + u.x = x + 1; + return u.y; +} + +_Complex __int128 +f7 (_BitInt(256) *x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.x = *x + 1; + return u.y; +} + +_Complex __int128 +f8 (_BitInt(254) *x) +{ + union U { _BitInt(254) x; _Complex __int128 y; } u; + u.x = *x + 1; + return u.y; +} + +_BitInt(256) +f9 (_Complex __int128 x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.y = x; + return u.x + 1; +} + +_BitInt(252) +f10 (_Complex __int128 x) +{ + union U { _BitInt(252) x; _Complex __int128 y; } u; + u.y = x; + return u.x + 1; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 256 +V +f11 (_BitInt(256) x) +{ + union U { _BitInt(256) x; V y; } u; + u.x = x; + return u.y; +} + +V +f12 (_BitInt(254) x) +{ + union U { _BitInt(254) x; V y; } u; + u.x = x; + return u.y; +} + +_BitInt(256) +f13 (V x) +{ + union U { _BitInt(256) x; V y; } u; + u.y = x; + return u.x; +} + +_BitInt(252) +f14 (V x) +{ + union U { _BitInt(252) x; V y; } u; + u.y = x; + return u.x; +} + +V +f15 (_BitInt(256) x) +{ + union U { _BitInt(256) x; V y; } u; + u.x = x + 1; + return u.y; +} + +V +f16 (_BitInt(254) x) +{ + union U { _BitInt(254) x; V y; } u; + u.x = x + 1; + return u.y; +} + +V +f17 (_BitInt(256) *x) +{ + union U { _BitInt(256) x; V y; } u; + u.x = *x + 1; + return u.y; +} + +V +f18 (_BitInt(254) *x) +{ + union U { _BitInt(254) x; V y; } u; + u.x = *x + 1; + return u.y; +} + +_BitInt(256) +f19 (V x) +{ + union U { _BitInt(256) x; V y; } u; + u.y = x; + return u.x + 1; +} + +_BitInt(252) +f20 (V x) +{ + union U { _BitInt(252) x; V y; } u; + u.y = x; + return u.x + 1; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 512 +W +f21 (_BitInt(512) x) +{ + union U { _BitInt(512) x; W y; } u; + u.x = x; + return u.y; +} + +W +f22 (_BitInt(509) x) +{ + union U { _BitInt(509) x; W y; } u; + u.x = x; + return u.y; +} + +_BitInt(512) +f23 (W x) +{ + union U { _BitInt(512) x; W y; } u; + u.y = x; + return u.x; +} + +_BitInt(506) +f24 (W x) +{ + union U { _BitInt(506) x; W y; } u; + u.y = x; + return u.x; +} + +W +f25 (_BitInt(512) x) +{ + union U { _BitInt(512) x; W y; } u; + u.x = x + 1; + return u.y; +} + +W +f26 (_BitInt(509) x) +{ + union U { _BitInt(509) x; W y; } u; + u.x = x + 1; + return u.y; +} + +W +f27 (_BitInt(512) *x) +{ + union U { _BitInt(512) x; W y; } u; + u.x = *x + 1; + return u.y; +} + +W +f28 (_BitInt(509) *x) +{ + union U { _BitInt(509) x; W y; } u; + u.x = *x + 1; + return u.y; +} + +_BitInt(512) +f29 (W x) +{ + union U { _BitInt(512) x; W y; } u; + u.y = x; + return u.x + 1; +} + +_BitInt(506) +f30 (W x) +{ + union U { _BitInt(506) x; W y; } u; + u.y = x; + return u.x + 1; +} +#endif