From patchwork Tue May 7 16:01:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1932554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c2ACDo6k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VYjhP6zPPz1xnS for ; Wed, 8 May 2024 02:01:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C742384AB52 for ; Tue, 7 May 2024 16:01: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 B73273858D1E for ; Tue, 7 May 2024 16:01:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B73273858D1E 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 B73273858D1E 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=1715097688; cv=none; b=tciirzOcCv2WenxJlSltlpWBNL06t7XlQWu8jfIqxQIIS7JjsuZZlL27Q+R/OP55Jm+0WJvGEIOZydjmgBi60SqbrtnzRnoqkuI6w98i7k04cM2/59SDxr0OgcC31CZVgV5I6GYB0vOTdyPnYeXS9ehQIbI04QgpSYalGGs/x7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715097688; c=relaxed/simple; bh=8x2ZgwKUHFSsnrL94JMhyLoJVY1+O+XXv5SOiAEH8NM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=a79066dO+SikkwM5DqYi+0G4O6KKp7S0K//RZv5iDfKm+ew5T9EEUvBxq5NoYO+XDnZK0F15pflLtrKYO/3ApAP9hEYMtF+Ku41ZZHwjh7KZn2tlETuPE+ZRcrgxDuFuaKcDK5YaB52Qn35CaE43BuQgC56Pw0727MZktWpjYP4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715097685; 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=/4RujmlQP9xar1cutqoZp9MnIi+NBDegN7OM4tP41wc=; b=c2ACDo6kFRy5BcD8p2pxVZPf9uc0LfXt4ju+q7yIxYdx/3J722wCkjp/gDRSxvE1KpNpMU be1/HHBCx3qguCtNamKwgddisip9UrdCav0oK9vJR7zGr8m7ALkmxjCHEU1BI/koJTAzmc h3zfVlRx+oqoddF/Kt0IPO0mT5uo++U= 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-216-8dN2hm5VN-uW1oVs7RkoNw-1; Tue, 07 May 2024 12:01:22 -0400 X-MC-Unique: 8dN2hm5VN-uW1oVs7RkoNw-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 5F0403802B8D; Tue, 7 May 2024 16:01:21 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23F85200AF76; Tue, 7 May 2024 16:01:21 +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 447G1JTe2351976 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 7 May 2024 18:01:19 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 447G1Jjj2351975; Tue, 7 May 2024 18:01:19 +0200 Date: Tue, 7 May 2024 18:01:18 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] expansion: Use __trunchfbf2 calls rather than __extendhfbf2 [PR114907] 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.9 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The HF and BF modes have the same size/precision and neither is a subset nor superset of the other. So, using either __extendhfbf2 or __trunchfbf2 is weird. The expansion apparently emits __extendhfbf2, but on the libgcc side we apparently have __trunchfbf2 implemented. I think it is easier to switch to using what is available rather than adding new entrypoints to libgcc, even alias, because this is backportable. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-05-07 Jakub Jelinek PR middle-end/114907 * expr.cc (convert_mode_scalar): Use trunc_optab rather than sext_optab for HF->BF conversions. * optabs-libfuncs.cc (gen_trunc_conv_libfunc): Likewise. * gcc.dg/pr114907.c: New test. Jakub --- gcc/expr.cc.jj 2024-04-09 09:29:04.000000000 +0200 +++ gcc/expr.cc 2024-05-06 13:21:33.933798494 +0200 @@ -355,8 +355,16 @@ convert_mode_scalar (rtx to, rtx from, i && REAL_MODE_FORMAT (from_mode) == &ieee_half_format)); if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode)) - /* Conversion between decimal float and binary float, same size. */ - tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab; + { + if (REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format + && REAL_MODE_FORMAT (from_mode) == &ieee_half_format) + /* libgcc implements just __trunchfbf2, not __extendhfbf2. */ + tab = trunc_optab; + else + /* Conversion between decimal float and binary float, same + size. */ + tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab; + } else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)) tab = sext_optab; else --- gcc/optabs-libfuncs.cc.jj 2024-01-03 11:51:31.739728303 +0100 +++ gcc/optabs-libfuncs.cc 2024-05-06 15:50:21.611027802 +0200 @@ -589,7 +589,9 @@ gen_trunc_conv_libfunc (convert_optab ta if (GET_MODE_CLASS (float_tmode) != GET_MODE_CLASS (float_fmode)) gen_interclass_conv_libfunc (tab, opname, float_tmode, float_fmode); - if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode)) + if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode) + && (REAL_MODE_FORMAT (float_tmode) != &arm_bfloat_half_format + || REAL_MODE_FORMAT (float_fmode) != &ieee_half_format)) return; if (GET_MODE_CLASS (float_tmode) == GET_MODE_CLASS (float_fmode)) --- gcc/testsuite/gcc.dg/pr114907.c.jj 2024-05-06 15:59:08.734958523 +0200 +++ gcc/testsuite/gcc.dg/pr114907.c 2024-05-06 16:02:38.914139829 +0200 @@ -0,0 +1,27 @@ +/* PR middle-end/114907 */ +/* { dg-do run } */ +/* { dg-options "" } */ +/* { dg-add-options float16 } */ +/* { dg-require-effective-target float16_runtime } */ +/* { dg-add-options bfloat16 } */ +/* { dg-require-effective-target bfloat16_runtime } */ + +__attribute__((noipa)) _Float16 +foo (__bf16 x) +{ + return (_Float16) x; +} + +__attribute__((noipa)) __bf16 +bar (_Float16 x) +{ + return (__bf16) x; +} + +int +main () +{ + if (foo (11.125bf16) != 11.125f16 + || bar (11.125f16) != 11.125bf16) + __builtin_abort (); +}