From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id A9F723857B86 for ; Wed, 31 Aug 2022 06:22:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A9F723857B86 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62d.google.com with SMTP id y3so26378408ejc.1 for ; Tue, 30 Aug 2022 23:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=ZM4MaYtP60Kbi0e5ytbj8lhj34SRrYsMrnQzaa1wsXw=; b=Y1y8n0k9ODlEYMCCCMJN8hxxbCWSIpwvQ3Hwa5MQQ5EsHhDI++M1lGsYs1/psD/73Y uO+LU9XNuYxT8PyWgk9aBUUwzYjCYaPx+Z5Gsd27lgBXQtwwVgQp/mQz/mFVRtOPCyrv waUEzMSScuZWRNanvP3WUTa25wG96C7UKm2EIGMyuKeYfbl1oEalpzSctl7ZxWVGKqhH JAHxlyAZ0oHQIFZMl8TZS2NmZ+7g6UaZwn7wlIInC5cVTB3yCwmvIJBZQiiWMXst26RQ UU+RFpigvpBueq36zHUPGLYtzi85MfMahSnEN5qkM/URITBDNhIrHgnI7PFjO0QKlsUK E5xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=ZM4MaYtP60Kbi0e5ytbj8lhj34SRrYsMrnQzaa1wsXw=; b=0e64C0ZueQWw5FsC4hdHFaks4eqSU63Cw6Vxv01ajvNpawBoxRPX+M3trnW07fG9tn KbWLKiuA9D2gzlTtRV8Hwbbc3/jYYg+f6SIkv/V5nU2BZXkkXTh5RkKM3JWSMy/uudT6 YTZwfLSXq0vkbhNLDEheRqSCIYpM11Edt48PJYkvVxYVWrtykqjjTw/ntD2nxV2WKA0n yuQzWwe57X+sfkZQ19Lz69KY8gvDAKXeWHJoklwGXezdHgoGxn1WAhlSkuMgtTootkwx 9DCKKIQutOu5zKeOPHAIFpmp0gb0b/UtP8qV+al7t3b3ckX9Sf0LY70CuIQ9HvN50WyO Gb6A== X-Gm-Message-State: ACgBeo0ZTt9AhDcM0fUxtozC619g/SC/9dBVn/gUNplJuQKXzg5/GqwU TT7/r/1PCBQIoE5DwGkfci+DdgTjS6IXC9W7KVw= X-Google-Smtp-Source: AA6agR4avClgMPwQSwNJyYmZrDzLxSLcFglZh+1U9iWjS8uDLcctGI8h0lmOC/+bEYralXdbbGrZzjWHq9ieilj/QJA= X-Received: by 2002:a17:906:8a68:b0:741:56b2:af42 with SMTP id hy8-20020a1709068a6800b0074156b2af42mr12022369ejc.488.1661926959465; Tue, 30 Aug 2022 23:22:39 -0700 (PDT) MIME-Version: 1.0 References: <20220830154301.1965174-1-aldyh@redhat.com> In-Reply-To: <20220830154301.1965174-1-aldyh@redhat.com> From: Richard Biener Date: Wed, 31 Aug 2022 08:22:27 +0200 Message-ID: Subject: Re: [COMMITTED] Improve union of ranges containing NAN. To: Aldy Hernandez Cc: GCC patches , Jakub Jelinek Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 Tue, Aug 30, 2022 at 5:43 PM Aldy Hernandez via Gcc-patches wrote: > > Previously [5,6] U NAN would just drop to VARYING. With this patch, > the resulting range becomes [5,6] with the NAN bit set to unknown. > > [I still have yet to decide what to do with intersections. ISTM, the > intersection of a known NAN with anything else should be a NAN, but it > could also be undefined (the empty set). I'll have to run some tests > and see. Currently, we drop to VARYING cause well... it's always safe > to give up;-).] Giving up in too many places will hide bugs in others for too long ... > gcc/ChangeLog: > > * value-range.cc (early_nan_resolve): Change comment. > (frange::union_): Handle union when one side is a NAN. > (range_tests_nan): Add tests for NAN union. > --- > gcc/value-range.cc | 44 ++++++++++++++++++++++++++++++++++---------- > 1 file changed, 34 insertions(+), 10 deletions(-) > > diff --git a/gcc/value-range.cc b/gcc/value-range.cc > index b6d6c62c06c..473139c6dbd 100644 > --- a/gcc/value-range.cc > +++ b/gcc/value-range.cc > @@ -403,7 +403,7 @@ early_nan_resolve (frange &r, const frange &other) > // There's nothing to do for both NANs. > if (r.get_nan ().yes_p () == other.get_nan ().yes_p ()) > return false; > - // But only one NAN complicates things. > + // ?? Perhaps the intersection of a NAN and anything is a NAN ??. > r.set_varying (r.type ()); > return true; > } > @@ -420,10 +420,22 @@ frange::union_ (const vrange &v) > *this = r; > return true; > } > - // ?? We could do better here. [5,6] U NAN should be [5,6] with the > - // NAN maybe bits set. For now, this is conservatively correct. > - if (get_nan ().yes_p () || r.get_nan ().yes_p ()) > - return early_nan_resolve (*this, r); > + > + // If one side has a NAN, the union is just the other side plus the > + // NAN bit. > + if (get_nan ().yes_p ()) > + { > + *this = r; > + // NOP if NAN already set. > + set_nan (fp_prop::VARYING); > + return true; > + } > + if (r.get_nan ().yes_p ()) > + { > + // NOP if NAN already set. > + set_nan (fp_prop::VARYING); > + return true; > + } > > bool changed = m_props.union_ (r.m_props); > > @@ -3520,6 +3532,7 @@ static void > range_tests_nan () > { > frange r0, r1; > + REAL_VALUE_TYPE q, r; > > // Equal ranges but with differing NAN bits are not equal. > r1 = frange_float ("10", "12"); > @@ -3537,13 +3550,24 @@ range_tests_nan () > ASSERT_FALSE (r0 == r0); > ASSERT_TRUE (r0 != r0); > > - // Make sure that combining NAN and INF doesn't give any crazy results. > + // [5,6] U NAN is [5,6] with an unknown NAN bit. > + r0 = frange_float ("5", "6"); > + r0.set_nan (fp_prop::NO); > + r1 = frange_nan (float_type_node); > + r0.union_ (r1); > + real_from_string (&q, "5"); > + real_from_string (&r, "6"); > + ASSERT_TRUE (real_identical (&q, &r0.lower_bound ())); > + ASSERT_TRUE (real_identical (&r, &r0.upper_bound ())); > + ASSERT_TRUE (r0.get_nan ().varying_p ()); > + > + // NAN U NAN = NAN > r0 = frange_nan (float_type_node); > - ASSERT_TRUE (r0.get_nan ().yes_p ()); > - r1 = frange_float ("+Inf", "+Inf"); > + r1 = frange_nan (float_type_node); > r0.union_ (r1); > - // [INF, INF] U NAN = VARYING > - ASSERT_TRUE (r0.varying_p ()); > + ASSERT_TRUE (real_isnan (&r0.lower_bound ())); > + ASSERT_TRUE (real_isnan (&r1.upper_bound ())); > + ASSERT_TRUE (r0.get_nan ().yes_p ()); > > // [INF, INF] ^ NAN = VARYING > r0 = frange_nan (float_type_node); > -- > 2.37.1 >