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 1BB373858D37 for ; Tue, 21 Mar 2023 12:56:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BB373858D37 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=1679403409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I6zX09S4rnoO6cgaIFtRUpXimvquPBLwBX5nadutwjU=; b=fZ1bJgrnoOZz7cAqIvqEKeygKaTlDmnIelJPw+eu5L7k+EgvkJnKZzNVB4Qf3yNuDw8G0u g2QM7Ovk722WuNoagBUvf065Bs8B8+jUn1z3aolj9ZaSvG1jvY0xdJ34vGtszjOH39rrJO kk3+4BjKRryr4sBM49mMV6iFcCu8/No= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-l7u4I3BnPBCWvjumjqLXCg-1; Tue, 21 Mar 2023 08:56:48 -0400 X-MC-Unique: l7u4I3BnPBCWvjumjqLXCg-1 Received: by mail-ed1-f72.google.com with SMTP id y24-20020aa7ccd8000000b004be3955a42eso22148968edt.22 for ; Tue, 21 Mar 2023 05:56:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679403407; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I6zX09S4rnoO6cgaIFtRUpXimvquPBLwBX5nadutwjU=; b=n40Q3aF52VsOFW5nwbEV8hgp3Lvy+SAYgky0DwFysRs7cCoFTTVLj+mS3aGiGRBstI Q5zvTap7N372Gh5SkhnioPKmrIRqPpmLbTR1Qmywf18CEg0WRdmV7nvnnNelfh2rjzrb f0b7GrIbuQ6agiFVBGjmZLx7JX8N2gEVIYLTMTuIG02Bmgr1z3qCKIT6DotRDYl8iYg6 zHMzNrgmBisNBuCAthiueKu8oce9EhimqI+RK3AaWfNpjMpf07vptrPH4RRrMAFphXIe 6p9sDj1F5MWxw0Kqp0Nq8FmWuloMB+iMiNzSkQ7I0EZXXBplkZv3Jq5JrpL44uyE5WBw WuEw== X-Gm-Message-State: AO0yUKU9EAFrs1/NZfzdghkKUXbAf8mnctqHXepFg/2+Gm8ud7ot/ISX G68ZJJBCYkspvsIFT3m534wIWiT65W3Rw46v9EckknVHXNLN+Mz4pwF1D5iOHJD66+vkunGtz/Q gyII728aGdA7+BSedkcebw4DWdjHgYqVuaw== X-Received: by 2002:a50:c3ce:0:b0:4fa:ce07:639f with SMTP id i14-20020a50c3ce000000b004face07639fmr1509067edf.5.1679403407595; Tue, 21 Mar 2023 05:56:47 -0700 (PDT) X-Google-Smtp-Source: AK7set/HG8UOAi2UBtthmAx3DCnl1L19DKR/JJJRfeCpw6AUBpEO9e/51c06/1X1xAsp6XK7tZin5GPLnRjf/o24Hlo= X-Received: by 2002:a50:c3ce:0:b0:4fa:ce07:639f with SMTP id i14-20020a50c3ce000000b004face07639fmr1509055edf.5.1679403407283; Tue, 21 Mar 2023 05:56:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Aldy Hernandez Date: Tue, 21 Mar 2023 13:56:36 +0100 Message-ID: Subject: Re: [PATCH] range-op-float: Fix up -ffinite-math-only range extension and don't extend into infinities [PR109008] To: Jakub Jelinek Cc: Richard Biener , gcc-patches@gcc.gnu.org, Andrew MacLeod X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.3 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 20, 2023 at 5:14=E2=80=AFPM Jakub Jelinek wr= ote: > > 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 AP= I 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 m= e ;-). > > > > > > Sure. The current state is that I think the actual bugs are fixed ex= cept > > > 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 cha= nge > > > 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) re= ally work as > > > infinities. Whenever we actually round that value to mode, it will b= ecome > > > 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 wou= ld > 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 ma= x, > perform real_arithmetic recurse on the argument replaced with > dconstninf/dconstinf and then depending on inf pick the mininum or maximu= m > of the two results (and carefully think about what to do if both operands > are min/max). LGTM. Aldy > > 2023-03-20 Jakub Jelinek > > * range-op-float.cc (frange_arithmetic): For !MODE_HAS_INFINITIES > types, pretend operands with minimum or maximum values are actual= ly > 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 =3D TYPE_MODE (type); > bool mode_composite =3D MODE_COMPOSITE_P (mode); > + const REAL_VALUE_TYPE *pop1 =3D &op1; > + const REAL_VALUE_TYPE *pop2 =3D &op2; > > - bool inexact =3D 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 =3D &dconstninf; > + else if (frange_val_is_max (op1, type)) > + pop1 =3D &dconstinf; > + if (frange_val_is_min (op2, type)) > + pop2 =3D &dconstninf; > + else if (frange_val_is_max (op2, type)) > + pop2 =3D &dconstinf; > + } > + > + bool inexact =3D real_arithmetic (&value, code, pop1, pop2); > real_convert (&result, mode, &value); > > // Be extra careful if there may be discrepancies between the > > > Jakub >