From patchwork Fri Sep 30 17:13:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp591147wrs; Fri, 30 Sep 2022 10:14:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eu4OZ0ObrG4Nr9XMdwMZQjTHbO6cB/VXq+vTt0CMsPIiJWZNTEIiTT5Cs266ymNy+dnox X-Received: by 2002:a17:907:3ea9:b0:787:f6aa:8ad5 with SMTP id hs41-20020a1709073ea900b00787f6aa8ad5mr4077743ejc.3.1664558073744; Fri, 30 Sep 2022 10:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664558073; cv=none; d=google.com; s=arc-20160816; b=bzaLWaReTZ3/ixc1bdxISrlb0c+wx7ZEGCk/TEPwqevs2EFpsps0wDy1Oeo4kNHwoN dKgswhjad8XzZQ4UO5V1g5aCXOhjZVPrPScZljwTAUk6j4wfROqjMq1pKhaa4tb7OrvY XKkSd4FPNZnlqvpESfE2DI9M+vvHig+WTU0JFaGrxUilXKFQ/FlIXdj/fF5fVteofYe0 bC/daHDuoq81HmTrhwau9/fsnRPP8DC8bK7nD7AanXVDL6rbKGbh2tSYduXrByUsPXew 64bBg+5/X2JKbvkqq5YTc6YwHzT2mh82ZA4sg+FdaRLWeuC5nUNR1Ox3EE6cR2l0upxi T2dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=X3gahAzKonIvrtGAD30fznuXNev1IhwsxnbtAKtNhhc=; b=Q+rQ04aMvlnD3tOK9H3evmDY9xhqaDfMV16fv2Z4WwLEu8OLV4ihdZwHW+hhD2lWah 87Njjp3s+G5UueJA790qHl5bNooso4f/PtT2oNLwhXUy82x3MM+n9ae7QohY5f/5YisB 4V6CnMXzDM3qJ4ZUX+SQDqP6VwQbVKr6ryR7TQXCWBolsFaumK+CtDfTfAR+A/9WgR1T yWN0UVGW1WT9tzEUNWA6p9noUX/+zTcR7d0UtJjsdQJl3IS+gT9NBrXXQYRU9U0LxChS m7Y8vqDzSj3CW89O0caGS58DOV5XruX9HzTLd3eYsLviJJCnMTRLo9PEu7jzQeoH+7ym QBAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="EGL/va78"; 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=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dn19-20020a17090794d300b007880167d7b1si2126466ejc.436.2022.09.30.10.14.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 10:14:33 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b="EGL/va78"; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A43BE385C338 for ; Fri, 30 Sep 2022 17:14:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A43BE385C338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664558072; bh=X3gahAzKonIvrtGAD30fznuXNev1IhwsxnbtAKtNhhc=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EGL/va7809kHING+s9dQOY3tdG50Al8q+Kc2JfCGTnXgzlDP3cfqSHM0guUBPIgnq DZF8p8kdXTxmcH9RdIahMPL8z8/NE6MMYnmUql/niDMNWJ1w6j466mmTdTvKgkRdAg UAjzb4h6HMTFauqOUV+1Dudnyb9ObHuxEZgcqgak= 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 BA2523858D1E for ; Fri, 30 Sep 2022 17:13:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BA2523858D1E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-nvVhqeULMyuKHJPhqhh2Hw-1; Fri, 30 Sep 2022 13:13:47 -0400 X-MC-Unique: nvVhqeULMyuKHJPhqhh2Hw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2167101A528; Fri, 30 Sep 2022 17:13:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 978821121315; Fri, 30 Sep 2022 17:13:46 +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 28UHDh2J090057 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 30 Sep 2022 19:13:44 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 28UHDgb9090056; Fri, 30 Sep 2022 19:13:42 +0200 Date: Fri, 30 Sep 2022 19:13:42 +0200 To: Jason Merrill Subject: [PATCH] arm, aarch64, csky: Fix C++ ICEs with _Float16 and __fp16 [PR107080] Message-ID: References: <60f5d708-a233-2c36-6f74-ae064fdf6ffd@redhat.com> MIME-Version: 1.0 In-Reply-To: <60f5d708-a233-2c36-6f74-ae064fdf6ffd@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: richard.sandiford@arm.com, Richard Earnshaw , gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745415646792687526?= X-GMAIL-MSGID: =?utf-8?q?1745415646792687526?= On Fri, Sep 30, 2022 at 09:54:49AM -0400, Jason Merrill wrote: > > Note, there is one further problem on aarch64/arm, types with HFmode > > (_Float16 and __fp16) are there mangled as Dh (which is standard > > Itanium mangling: > > ::= Dh # IEEE 754r half-precision floating point (16 bits) > > ::= DF _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits) > > so in theory is also ok, but DF16_ is more specific. Should we just > > change Dh to DF16_ in those backends, or should __fp16 there be distinct > > type from _Float16 where __fp16 would mangle Dh and _Float16 DF16_ ? > > You argued for keeping __float128 separate from _Float128, does the same > argument not apply to this case? Actually, they already were distinct types that just mangled the same. So the same issue that had to be solved on i?86, ia64 and rs6000 for _Float64x vs. long double is a problem on arm and aarch64 with _Float16 vs. __fp16. The following patch fixes it. > > And there is csky, which mangles __fp16 (but only if type's name is __fp16, > > not _Float16) as __fp16, that looks clearly invalid to me as it isn't > > valid in the mangling grammar. So perhaps just nuke csky's mangle_type > > and have it mangled as DF16_ by the generic code? And seems even on csky __fp16 is distinct type from _Float16 (which is a good thing for consistency, these 3 targets are the only ones that have __fp16 type), so instead the patch handles it the same as on arm/aarch64, Dh mangling for __fp16 and DF16_ for _Float16. Tested with cross-compilers, ok for trunk? 2022-09-30 Jakub Jelinek PR c++/107080 * config/arm/arm.cc (arm_mangle_type): Mangle just __fp16 as Dh and _Float16 as DF16_. * config/aarch64/aarch64.cc (aarch64_mangle_type): Likewise. * config/csky/csky.cc (csky_init_builtins): Fix a comment typo. (csky_mangle_type): Mangle __fp16 as Dh and _Float16 as DF16_ rather than mangling __fp16 as __fp16. * g++.target/arm/pr107080.C: New test. * g++.target/aarch64/pr107080.C: New test. Jakub --- gcc/config/arm/arm.cc.jj 2022-09-29 18:11:28.746750048 +0200 +++ gcc/config/arm/arm.cc 2022-09-30 19:01:48.774286551 +0200 @@ -30359,6 +30359,8 @@ arm_mangle_type (const_tree type) /* Half-precision floating point types. */ if (TREE_CODE (type) == REAL_TYPE && TYPE_PRECISION (type) == 16) { + if (TYPE_MAIN_VARIANT (type) == float16_type_node) + return NULL; if (TYPE_MODE (type) == BFmode) return "u6__bf16"; else --- gcc/config/aarch64/aarch64.cc.jj 2022-09-29 18:11:34.806667210 +0200 +++ gcc/config/aarch64/aarch64.cc 2022-09-30 19:02:02.079108171 +0200 @@ -20664,6 +20664,8 @@ aarch64_mangle_type (const_tree type) /* Half-precision floating point types. */ if (TREE_CODE (type) == REAL_TYPE && TYPE_PRECISION (type) == 16) { + if (TYPE_MAIN_VARIANT (type) == float16_type_node) + return NULL; if (TYPE_MODE (type) == BFmode) return "u6__bf16"; else --- gcc/config/csky/csky.cc.jj 2022-09-08 13:01:19.239779562 +0200 +++ gcc/config/csky/csky.cc 2022-09-30 19:06:09.126794587 +0200 @@ -7300,7 +7300,7 @@ csky_init_cumulative_args (CUMULATIVE_AR void csky_init_builtins (void) { - /* Inint fp16. */ + /* Init fp16. */ static tree csky_floatHF_type_node = make_node (REAL_TYPE); TYPE_PRECISION (csky_floatHF_type_node) = GET_MODE_PRECISION (HFmode); layout_type (csky_floatHF_type_node); @@ -7313,10 +7313,10 @@ csky_init_builtins (void) static const char * csky_mangle_type (const_tree type) { - if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && DECL_NAME (TYPE_NAME (type)) - && !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))), "__fp16")) - return "__fp16"; + if (TREE_CODE (type) == REAL_TYPE + && TYPE_PRECISION (type) == 16 + && TYPE_MAIN_VARIANT (type) != float16_type_node) + return "Dh"; /* Use the default mangling. */ return NULL; --- gcc/testsuite/g++.target/arm/pr107080.C.jj 2022-09-30 18:56:08.885797047 +0200 +++ gcc/testsuite/g++.target/arm/pr107080.C 2022-09-30 18:58:07.812221153 +0200 @@ -0,0 +1,16 @@ +// PR c++/107080 +// { dg-do compile } +// { dg-options "-mfp16-format=ieee" } + +template +int +foo (T x, T1 y) +{ + return 3; +} + +int +main () +{ + return (foo (0.0f16, 0.0f16) + foo (0.0f16, (__fp16) 0.0)) != 6; +} --- gcc/testsuite/g++.target/aarch64/pr107080.C.jj 2022-09-30 18:56:08.885797047 +0200 +++ gcc/testsuite/g++.target/aarch64/pr107080.C 2022-09-30 18:56:04.805851530 +0200 @@ -0,0 +1,16 @@ +// PR c++/107080 +// { dg-do compile } +// { dg-options "" } + +template +int +foo (T x, T1 y) +{ + return 3; +} + +int +main () +{ + return (foo (0.0f16, 0.0f16) + foo (0.0f16, (__fp16) 0.0)) != 6; +}