From patchwork Wed Oct 27 13:20:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 46704 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6EE633857C48 for ; Wed, 27 Oct 2021 13:21:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6EE633857C48 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635340873; bh=UbSVjokdt+XP1/ul+72PuxV+SxhhEKn1yTbg66qCF6s=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=GainmwyO+KKYK9SHMumKBXP/Lvu6QNjExj+0OW7nzTB+EZksncgEafW8n4HzWCrRy lFbMU/oHwRootKdz9Gnizaa71EkhONvTtYFy7eMvgUC7G2sF6syR+2xVqqHBbwuiZZ 6WPn/bAQtecNynSwwZIvdmkvXg/MVsSBcFqC/jKs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id AE9A03857C6B for ; Wed, 27 Oct 2021 13:20:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AE9A03857C6B Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EB76C1FD50; Wed, 27 Oct 2021 13:20:29 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CF0BA13D55; Wed, 27 Oct 2021 13:20:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZkcMMR1SeWFHJAAAMHmgww (envelope-from ); Wed, 27 Oct 2021 13:20:29 +0000 Date: Wed, 27 Oct 2021 15:20:29 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/57245 - honor -frounding-math in real truncation Message-ID: <99s854-94r4-8823-6n80-nq081641son@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: joseph@codesourcery.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following honors -frounding-math when converting a FP constant to another FP type. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? I wonder what a good way to test this in a portable way, the bugreport unfortunately didn't contain something executable and I don't see much -frounding-math test coverage to copy from. Thanks, Richard. 2021-10-27 Richard Biener PR middle-end/57245 * fold-const.c (fold_convert_const_real_from_real): Honor -frounding-math if the conversion is not exact. --- gcc/fold-const.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ff23f12f33c..c7aebf9cc7e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2139,6 +2139,12 @@ fold_convert_const_real_from_real (tree type, const_tree arg1) && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg1))) return NULL_TREE; + /* With flag_rounding_math we shuld respect the current rounding mode + unless the conversion is exact. */ + if (HONOR_SIGN_DEPENDENT_ROUNDING (arg1) + && !exact_real_truncate (TYPE_MODE (type), &TREE_REAL_CST (arg1))) + return NULL_TREE; + real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1)); t = build_real (type, value);