From patchwork Tue Oct 15 11:05: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: 1997354 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=Flu+w1WR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XSWVy30Dpz1xvK for ; Tue, 15 Oct 2024 22:06:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 040303858CD1 for ; Tue, 15 Oct 2024 11:06:14 +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 ESMTP id 548C63858D20 for ; Tue, 15 Oct 2024 11:05:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 548C63858D20 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 548C63858D20 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=1728990351; cv=none; b=VBGJUjiziJtQ8ofA/hzSo2ZQCCD+9LIL3FsngQBuIGHYLEAQvS+bTxjkiHTY/Ge5imH5o2UDZAhh8u98FhEj02Y5AE44Xf7jHutMWttQVYnUqxx6FR6XoayL2KEyD1rnweL+NDwyhVRQnLmk2IUHiWVnetxghMe5w3bZMRpwTd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728990351; c=relaxed/simple; bh=cKWZ2ooZ7tyMBmiH4zvGJCO30lA7PZ7+oogwBP8TNf4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=GCnTdDjzEsmBdBy3YeSGmgM00wThl5y4gYz/WFEdgkMXPN14YA22EWfSLV8NCzzr5q443iOLiwNAXwtZkoYA2pykBP9sKR8GsvAPCBy14pEfSanLtHDyzUtxaOSC8BvJWHqxW+XXCJLeKp80vwuitfD2oIGAfhNv5KeX/8Q0Uzk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728990343; 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:in-reply-to:in-reply-to: references:references; bh=E6/JaJPIuqvkcg9cOo+oama0DYGr9I7+3CrnNf0bf24=; b=Flu+w1WRxM+GazQuXooqbEioafL1EgIpQ692CRb7D1RyTBvWop7A+vyBtj/7WksDu+xnfk 7oQZ3goB5hJ7op385VyqTT1WwSv/JxwpgmFBIyM32+z+bkPNgSuqhAIbQ7NiLXNO30fwu/ /Ph0dd6TbOoWUtR8CK61cCFF/ZrCETs= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-LdRxqR9oMbysYA7vEpaRPw-1; Tue, 15 Oct 2024 07:05:38 -0400 X-MC-Unique: LdRxqR9oMbysYA7vEpaRPw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9C6491955F79; Tue, 15 Oct 2024 11:05:37 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D61B419560AE; Tue, 15 Oct 2024 11:05:36 +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 49FB5Xjj2889484 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 15 Oct 2024 13:05:33 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49FB5XIW2889483; Tue, 15 Oct 2024 13:05:33 +0200 Date: Tue, 15 Oct 2024 13:05:32 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: Further fma negation fixes [PR116891] Message-ID: References: <20241014061402.028DE13A51@imap1.dmz-prg2.suse.org> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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 On Mon, Oct 14, 2024 at 08:53:29AM +0200, Jakub Jelinek wrote: > > PR middle-end/116891 > > * match.pd ((negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)): > > Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING. > > Guess it would be nice to have a testcase which FAILs without the patch and > PASSes with it, but it can be added later. I've added such a testcase now, and additionally found the fix only fixed one of the 4 problematic similar cases. Here is a patch which fixes the others too and adds the testcases. fma-pr116891.c FAILed without your patch, FAILs with your patch too (but only due to the bar/baz/qux checks) and PASSes with the patch. Ok for trunk if it passes full bootstrap/regtest? 2024-10-15 Jakub Jelinek PR middle-end/116891 * match.pd ((negate (fmas@3 @0 @1 @2)) -> (IFN_FNMS @0 @1 @2)): Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING. ((negate (IFN_FMS@3 @0 @1 @2)) -> (IFN_FNMA @0 @1 @2)): Likewise. ((negate (IFN_FNMA@3 @0 @1 @2)) -> (IFN_FMS @0 @1 @2)): Likewise. * gcc.dg/pr116891.c: New test. * gcc.target/i386/fma-pr116891.c: New test. Jakub --- gcc/match.pd.jj 2024-10-15 12:50:47.699905473 +0200 +++ gcc/match.pd 2024-10-15 12:57:19.547400416 +0200 @@ -9452,7 +9452,7 @@ (define_operator_list SYNC_FETCH_AND_AND (IFN_FNMS @0 @1 @2)) (simplify (negate (fmas@3 @0 @1 @2)) - (if (single_use (@3)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) (IFN_FNMS @0 @1 @2)))) (simplify @@ -9466,7 +9466,7 @@ (define_operator_list SYNC_FETCH_AND_AND (IFN_FNMA @0 @1 @2)) (simplify (negate (IFN_FMS@3 @0 @1 @2)) - (if (single_use (@3)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) (IFN_FNMA @0 @1 @2))) (simplify @@ -9480,7 +9480,7 @@ (define_operator_list SYNC_FETCH_AND_AND (IFN_FMS @0 @1 @2)) (simplify (negate (IFN_FNMA@3 @0 @1 @2)) - (if (single_use (@3)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) (IFN_FMS @0 @1 @2))) (simplify --- gcc/testsuite/gcc.dg/pr116891.c.jj 2024-10-15 12:31:57.619723244 +0200 +++ gcc/testsuite/gcc.dg/pr116891.c 2024-10-15 12:56:37.809987933 +0200 @@ -0,0 +1,47 @@ +/* PR middle-end/116891 */ +/* { dg-do run } */ +/* { dg-require-effective-target fenv } */ +/* { dg-require-effective-target hard_float } */ +/* { dg-require-effective-target c99_runtime } */ +/* { dg-options "-O2 -frounding-math" } */ + +#include + +__attribute__((noipa)) double +foo (double x, double y, double z) +{ + return -__builtin_fma (-x, y, -z); +} + +__attribute__((noipa)) double +bar (double x, double y, double z) +{ + return -__builtin_fma (-x, y, z); +} + +__attribute__((noipa)) double +baz (double x, double y, double z) +{ + return -__builtin_fma (x, y, -z); +} + +__attribute__((noipa)) double +qux (double x, double y, double z) +{ + return -__builtin_fma (x, y, z); +} + +int +main () +{ +#if defined (FE_DOWNWARD) && __DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024 + fesetround (FE_DOWNWARD); + double a = foo (-0x1.p256, 0x1.p256, 0x1.p-256); + if (a != -__builtin_nextafter (0x1p256 * 0x1p256, 0.)) + __builtin_abort (); + if (a != bar (-0x1.p256, 0x1.p256, -0x1.p-256) + || a != baz (0x1.p256, 0x1.p256, 0x1.p-256) + || a != qux (0x1.p256, 0x1.p256, -0x1.p-256)) + __builtin_abort (); +#endif +} --- gcc/testsuite/gcc.target/i386/fma-pr116891.c.jj 2024-10-15 12:42:39.711719596 +0200 +++ gcc/testsuite/gcc.target/i386/fma-pr116891.c 2024-10-15 12:44:56.692806834 +0200 @@ -0,0 +1,19 @@ +/* PR middle-end/116891 */ +/* { dg-do run } */ +/* { dg-require-effective-target fenv } */ +/* { dg-require-effective-target hard_float } */ +/* { dg-require-effective-target c99_runtime } */ +/* { dg-require-effective-target fma } */ +/* { dg-options "-O2 -mfma -frounding-math" } */ + +#include +#include "fma-check.h" + +#define main() do_main () +#include "../../gcc.dg/pr116891.c" + +static void +fma_test (void) +{ + do_main (); +}