From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E47F23858C27 for ; Wed, 27 Oct 2021 13:41:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E47F23858C27 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-sOw0GRcnOvK2Kcn9ajd4bQ-1; Wed, 27 Oct 2021 09:41:32 -0400 X-MC-Unique: sOw0GRcnOvK2Kcn9ajd4bQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57EEA100C66E; Wed, 27 Oct 2021 13:41:31 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC55F60BF1; Wed, 27 Oct 2021 13:41:30 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 19RDfRhO1020722 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 27 Oct 2021 15:41:28 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 19RDfQ5A1020721; Wed, 27 Oct 2021 15:41:26 +0200 Date: Wed, 27 Oct 2021 15:41:26 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org, joseph@codesourcery.com Subject: Re: [PATCH] middle-end/57245 - honor -frounding-math in real truncation Message-ID: <20211027134126.GI304296@tucnak> Reply-To: Jakub Jelinek References: <99s854-94r4-8823-6n80-nq081641son@fhfr.qr> MIME-Version: 1.0 In-Reply-To: <99s854-94r4-8823-6n80-nq081641son@fhfr.qr> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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-List-Received-Date: Wed, 27 Oct 2021 13:41:37 -0000 On Wed, Oct 27, 2021 at 03:20:29PM +0200, Richard Biener via Gcc-patches wrote: > 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. E.g. following tests call fesetround, use fenv effective target etc.: torture/fp-int-convert-float128-timode-3.c: fesetround (FE_TOWARDZERO); torture/fp-int-convert-timode-2.c: fesetround (FE_DOWNWARD); torture/fp-int-convert-timode-3.c: fesetround (FE_UPWARD); torture/fp-int-convert-timode-4.c: fesetround (FE_TOWARDZERO); And the test can just hardcode one or more common float/double etc. configurations, checked using __{FLT,DBL}_{DIG,MANT_DIG,RADIX,MIN_EXP,MAX_EXP}__ etc. macros. Say just test double to float conversions of some specific values assuming float is IEEE754 single precicion and double is IEEE754 double precision in all the 4 rounding modes. > 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 s/shuld/should/ > + 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); Jakub