From patchwork Tue Jun 8 19:10:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1489601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=mghW9n9F; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G00pf2yJ2z9vFR for ; Wed, 9 Jun 2021 05:36:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26C013985038 for ; Tue, 8 Jun 2021 19:36:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 0B3F43983001 for ; Tue, 8 Jun 2021 19:10:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B3F43983001 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LNuVSgE8Gm4M9a7VqOnTzlIv7GNUEG4jgV9imaS0nxI=; b=mghW9n9F+zmqqu4U7CcVkporhC 77i1ZAGV1uzb1V+RhzmVAS86FLxXUfOod9h8SpAVLUvleqTBRxapQjVnSl+FbOCdGTIi6Fgtv+Fzf Efqum7AFSEOBNVzW50f9Px6Rp6njCuXmaz5lmgRqe35idb5mvjdSBtUdYyh71yGhF63BXC4bt18vc pNHE93RcvnBATNpo8NjoJSDJEPA6Lpw78qTy6MKImS1NlXi0kufU3ml3hraJCsQQ1YoLJ+jEAVAn8 CG/VG1eMQV2Q2J1e9IXbSdWX69kbhVDyITSZSdqj2d6cYMOSN65wluId+WMaPr+uQOsRkJnqptLmU 7mzjQldA==; Received: from [185.62.158.67] (port=57641 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lqh7K-0003C1-5u for gcc-patches@gcc.gnu.org; Tue, 08 Jun 2021 15:10:26 -0400 From: "Roger Sayle" To: Subject: [PATCH] PR middle-end/53267: Constant fold BUILT_IN_FMOD. Date: Tue, 8 Jun 2021 20:10:24 +0100 Message-ID: <027d01d75c99$efdc68b0$cf953a10$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AddcmXust4x5euDzRJiBdlG3UK4h6Q== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here's a three line patch to implement constant folding for fmod, fmodf and fmodl, which resolves an enhancement request from 2012. The following patch has been tested on x86_64-pc-linux-gnu with a make bootstrap and make -k check with no new failures. Ok for mainline? 2020-06-08 Roger Sayle gcc/ChangeLog PR middle-end/53267 * fold-const-call.c (fold_const_call_sss) [CASE_CFN_FMOD]: Support evaluation of fmod/fmodf/fmodl at compile-time. gcc/testsuite/ChangeLog * gcc.dg/builtins-70.c: New test. Roger --- Roger Sayle NextMove Software Cambridge, UK /* Copyright (C) 2021 Free Software Foundation. Check that constant folding of built-in fmod functions doesn't break anything and produces the expected results. /* { dg-do link } */ /* { dg-options "-O2 -ffast-math" } */ extern void link_error(void); extern double fmod(double,double); extern float fmodf(float,float); extern long double fmodl(long double,long double); int main() { if (fmod (6.5, 2.3) < 1.8999 || fmod (6.5, 2.3) > 1.9001) link_error (); if (fmod (-6.5, 2.3) < -1.9001 || fmod (-6.5, 2.3) > -1.8999) link_error (); if (fmod (6.5, -2.3) < 1.8999 || fmod (6.5, -2.3) > 1.9001) link_error (); if (fmod (-6.5, -2.3) < -1.9001 || fmod (-6.5, -2.3) > -1.8999) link_error (); if (fmodf (6.5f, 2.3f) < 1.8999f || fmodf (6.5f, 2.3f) > 1.9001f) link_error (); if (fmodf (-6.5f, 2.3f) < -1.9001f || fmodf (-6.5f, 2.3f) > -1.8999f) link_error (); if (fmodf (6.5f, -2.3f) < 1.8999f || fmodf (6.5f, -2.3f) > 1.9001f) link_error (); if (fmodf (-6.5f, -2.3f) < -1.9001f || fmodf (-6.5f, -2.3f) > -1.8999f) link_error (); if (fmodl (6.5l, 2.3l) < 1.8999l || fmod (6.5l, 2.3l) > 1.9001l) link_error (); if (fmodl (-6.5l, 2.3l) < -1.9001l || fmod (-6.5l, 2.3l) > -1.8999l) link_error (); if (fmodl (6.5l, -2.3l) < 1.8999l || fmod (6.5l, -2.3l) > 1.9001l) link_error (); if (fmodl (-6.5l, -2.3l) < -1.9001l || fmod (-6.5l, -2.3l) > -1.8999l) link_error (); return 0; } diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index a1d70b6..d6cb9b1 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -1375,6 +1375,9 @@ fold_const_call_sss (real_value *result, combined_fn fn, CASE_CFN_FDIM: return do_mpfr_arg2 (result, mpfr_dim, arg0, arg1, format); + CASE_CFN_FMOD: + return do_mpfr_arg2 (result, mpfr_fmod, arg0, arg1, format); + CASE_CFN_HYPOT: return do_mpfr_arg2 (result, mpfr_hypot, arg0, arg1, format);