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 0C41A3858034 for ; Wed, 27 Oct 2021 14:45:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0C41A3858034 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-588-iypPCIn5MmO23I9CKeGkbg-1; Wed, 27 Oct 2021 10:45:00 -0400 X-MC-Unique: iypPCIn5MmO23I9CKeGkbg-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 76C461B18BD2; Wed, 27 Oct 2021 14:44:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ABCD60BF1; Wed, 27 Oct 2021 14:44:58 +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 19REitK11021416 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 27 Oct 2021 16:44:55 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 19REirCB1021415; Wed, 27 Oct 2021 16:44:53 +0200 Date: Wed, 27 Oct 2021 16:44:53 +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: <20211027144453.GK304296@tucnak> Reply-To: Jakub Jelinek References: <99s854-94r4-8823-6n80-nq081641son@fhfr.qr> <20211027134126.GI304296@tucnak> <586429q7-q921-rs24-9o1-818or9722p4o@fhfr.qr> MIME-Version: 1.0 In-Reply-To: <586429q7-q921-rs24-9o1-818or9722p4o@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 14:45:07 -0000 On Wed, Oct 27, 2021 at 04:29:38PM +0200, Richard Biener wrote: > So something like the following below? Note I have to fix > simplify_const_unary_operation to not perform the invalid constant > folding with (not worrying about the exact conversion case - I doubt > any of the constant folding is really relevant on RTL these days, > maybe we should simply punt for all unary float-float ops when either > mode has sign dependent rounding modes) > > diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c > index bbbd6b74942..9522a31570e 100644 > --- a/gcc/simplify-rtx.c > +++ b/gcc/simplify-rtx.c > @@ -2068,6 +2073,9 @@ simplify_const_unary_operation (enum rtx_code code, > machine_mode mode, > and the operand is a signaling NaN. */ > if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d)) > return NULL_RTX; > + /* Or if flag_rounding_math is on. */ > + if (HONOR_SIGN_DEPENDENT_ROUNDING (mode)) > + return NULL_RTX; > d = real_value_truncate (mode, d); > break; Won't this stop folding of truncations that are never a problem? I mean at least if the wider float mode constant is exactly representable in the narrower float mode, no matter what rounding mode is used the value will be always the same... And people use float f = 1.0; or float f = 1.25; etc. a lot. So perhaps again if (HONOR_SIGN_DEPENDENT_ROUNDING (mode) && !exact_real_truncate (mode, &d)) return NULL_RTX; ? > /* PR57245 */ > /* { dg-do run } */ > /* { dg-require-effective-target fenv } */ > /* { dg-additional-options "-frounding-math" } */ > > #include > #include > > int > main () > { Roughly yes. Some tests also do #ifdef FE_*, so in your case > #if __DBL_MANT_DIG__ == 53 && __FLT_MANT_DIG__ == 24 +#ifdef FE_UPWARD > fesetround (FE_UPWARD); > float f = 1.3; > if (f != 0x1.4ccccep+0f) > __builtin_abort (); +#endif +#ifdef FE_TONEAREST etc. > fesetround (FE_TONEAREST); > /* Use different actual values so the bogus CSE we perform does not > break things. */ > f = 1.33; > if (f != 0x1.547ae2p+0f) > abort (); > fesetround (FE_DOWNWARD); > f = 1.333; > if (f != 0x1.553f7cp+0f) > abort (); > fesetround (FE_TOWARDZERO); > f = 1.3333; > if (f != 0x1.555326p+0f) > abort (); > #endif > return 0; > } Jakub