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 3CB953858436 for ; Mon, 20 Mar 2023 16:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CB953858436 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679328868; 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=mMHFvFrKO3irLA/uh2ib3oZDh26ueZoLrW1spUBNim8=; b=UlrUMvbWlo5LdhCjwYIRZRwPSneJOM4rkecQYs/TZz5SVtg1SV93YByhy6xMTxY33IEjrc w2lqf3NovxPiThp0ER8Y4eOh+jSTxRVqoTGNI0nvBofY8ZZbEtXL0yPWy4+z2p5vHikOX4 aQs6UKSAIcGGlvwy4KOkF42vRZL/hUo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-tvOUOGYdOJanKmMG9lmi1w-1; Mon, 20 Mar 2023 12:14:25 -0400 X-MC-Unique: tvOUOGYdOJanKmMG9lmi1w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44CA5886064; Mon, 20 Mar 2023 16:14:25 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 08124140EBF4; Mon, 20 Mar 2023 16:14:24 +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 32KGEMtl3123736 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 17:14:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32KGELEk3123735; Mon, 20 Mar 2023 17:14:21 +0100 Date: Mon, 20 Mar 2023 17:14:21 +0100 From: Jakub Jelinek To: Aldy Hernandez Cc: Richard Biener , gcc-patches@gcc.gnu.org, Andrew MacLeod Subject: Re: [PATCH] range-op-float: Fix up -ffinite-math-only range extension and don't extend into infinities [PR109008] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Mar 13, 2023 at 09:41:47AM +0100, Aldy Hernandez wrote: > On 3/13/23 09:06, Jakub Jelinek wrote: > > On Mon, Mar 13, 2023 at 08:59:15AM +0100, Aldy Hernandez wrote: > > > > Yes, sure - I just noticed that we're forced to use high-level API for > > > > something that's quite low-level and should be internal (a range > > > > "breaking" internal consistency checks). > > > > > > Yeah, let's fix the API. No sense hacking around things if what we need is > > > to tweak the design. > > > > > > I don't like hacking around things. It always comes back to bite me ;-). > > > > Sure. The current state is that I think the actual bugs are fixed except > > for the !MODE_HAS_INFINITIES case which people rarely use, so fixing up the > > API can wait even to next release. > > > > For !MODE_HAS_INFINITIES, I wonder if the best fix wouldn't be to change > > set and a few other spots, so that if the boundaries are > > real_min_representable/real_max_representable, we widen them to -inf and inf > > and change frange_val_min/max to also be dconstninf/dconstinf for > > !MODE_HAS_INFINITIES, because the min/max for that case (probably) really work as > > infinities. Whenever we actually round that value to mode, it will become > > real_min_representable/real_max_representable again. > > But that can also wait a week. > > That sounds very reasonable. It would remove special casing and would make > the code easier to read. For that matter, that was what I had in the > original implementation. I think we don't want to remove the special casing for -ffinite-math-only on types which do support infinities. Thinking further on it, perhaps for !MODE_HAS_INFINITIES a better fix would be to do something like the patch below. Consider say having a range of VAX float type: #define M0 -FLT_MAX #define M1 nextafterf (F0, FLT_MAX) #define M2 nextafterf (M1, FLT_MAX) [M2, M2] - [M0, M1] Or perhaps if one or both of the operands are in such a case a min and max, perform real_arithmetic recurse on the argument replaced with dconstninf/dconstinf and then depending on inf pick the mininum or maximum of the two results (and carefully think about what to do if both operands are min/max). 2023-03-20 Jakub Jelinek * range-op-float.cc (frange_arithmetic): For !MODE_HAS_INFINITIES types, pretend operands with minimum or maximum values are actually infinities. --- gcc/range-op-float.cc.jj 2023-03-10 12:40:19.673108938 +0100 +++ gcc/range-op-float.cc 2023-03-20 16:58:36.604981486 +0100 @@ -313,8 +313,26 @@ frange_arithmetic (enum tree_code code, REAL_VALUE_TYPE value; enum machine_mode mode = TYPE_MODE (type); bool mode_composite = MODE_COMPOSITE_P (mode); + const REAL_VALUE_TYPE *pop1 = &op1; + const REAL_VALUE_TYPE *pop2 = &op2; - bool inexact = real_arithmetic (&value, code, &op1, &op2); + if (!MODE_HAS_INFINITIES (mode)) + { + // If mode doesn't have infinities, the minimum and maximum + // values are saturating. Pretend for real_arithmetic such + // values are actual infinities. real_convert will then + // canonicalize the result not to be an infinity. + if (frange_val_is_min (op1, type)) + pop1 = &dconstninf; + else if (frange_val_is_max (op1, type)) + pop1 = &dconstinf; + if (frange_val_is_min (op2, type)) + pop2 = &dconstninf; + else if (frange_val_is_max (op2, type)) + pop2 = &dconstinf; + } + + bool inexact = real_arithmetic (&value, code, pop1, pop2); real_convert (&result, mode, &value); // Be extra careful if there may be discrepancies between the Jakub