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 96A14385841C for ; Fri, 11 Nov 2022 18:11:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96A14385841C 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=1668190315; 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; bh=USNA+4Z7/gu0qfit/FIc8uMz50lHYMTGb3O2A9pl6uU=; b=C1VZde63eN0wPO4v5HWYKTb7J4Equ4fwigpMh7SWYacGzXs8Mq0xRfnSKFzQBWKKias7cz IgaqkGj+FvTnHwX7M5MIRx1DAfBWBzH4rfC/9btxEcm9upAZPiHmRVwtq1J5lp0U9G5vrc 1D1SVdJ5qnck4Dq51YeagDrgdoo73UA= 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-308-8ri4Bbt3N4qZYPx5b3OGmA-1; Fri, 11 Nov 2022 13:11:53 -0500 X-MC-Unique: 8ri4Bbt3N4qZYPx5b3OGmA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEE2F811E67 for ; Fri, 11 Nov 2022 18:11:53 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56F3940C845B; Fri, 11 Nov 2022 18:11:53 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 2ABIBopm278583 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 11 Nov 2022 19:11:51 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2ABIBon2278582; Fri, 11 Nov 2022 19:11:50 +0100 From: Aldy Hernandez To: Jakub Jelinek Cc: GCC patches , Andrew MacLeod , Aldy Hernandez Subject: [PATCH] [range-ops] Add ability to represent open intervals in frange. Date: Fri, 11 Nov 2022 19:11:47 +0100 Message-Id: <20221111181147.278546-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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_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: Currently we represent < and > with a closed interval. So < 3.0 is represented as [-INF, +3.0]. This means 3.0 is included in the range, and though not ideal, is conservatively correct. Jakub has found a couple cases where properly representing < and > would help optimizations and tests, and this patch allows representing open intervals with real_nextafter. There are a few caveats. First, we leave MODE_COMPOSITE_P types pessimistically as a closed interval. Second, for -ffinite-math-only, real_nextafter will will saturate the maximum representable number into +INF. However, this will still do the right thing, as frange::set() will crop things appropriately. Finally, and most frustratingly, representing < and > -+0.0 is problematic because we flush denormals to zero. Let me explain... real_nextafter(+0.0, +INF) gives 0x0.8p-148 as expected, but setting a range to this value yields [+0.0, 0x0.8p-148] because of the flushing. On the other hand, real_nextafter(+0.0, -INF) (surprisingly) gives -0.0.8p-148, but setting a range to that value yields [-0.0x8p-148, -0.0]. I say surprising, because according to cppreference.com, std::nextafter(+0.0, -INF) should give -0.0. But that's neither here nor there because our flushing denormals to zero prevents us from even representing ranges involving small values around 0.0. We ultimately end up with ranges looking like this: > +0.0 => [+0.0, INF] > -0.0 => [+0.0, INF] < +0.0 => [-INF, -0.0] < -0.0 => [-INF, -0.0] I suppose this is no worse off that what we had before with closed intervals. One could even argue that we're better because we at least have the right sign now ;-). All other (non-zero) values look sane. Lightly tested. Thoughts? gcc/ChangeLog: * range-op-float.cc (build_lt): Adjust with frange_nextafter instead of default to a closed range. (build_gt): Same. --- gcc/range-op-float.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 380142b4c14..402393097b2 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -381,9 +381,17 @@ build_lt (frange &r, tree type, const frange &val) r.set_undefined (); return false; } - // We only support closed intervals. + REAL_VALUE_TYPE ninf = frange_val_min (type); - r.set (type, ninf, val.upper_bound ()); + REAL_VALUE_TYPE prev = val.upper_bound (); + machine_mode mode = TYPE_MODE (type); + // Default to the conservatively correct closed ranges for + // MODE_COMPOSITE_P, otherwise use nextafter. Note that for + // !HONOR_INFINITIES, nextafter will yield -INF, but frange::set() + // will crop the range appropriately. + if (!MODE_COMPOSITE_P (mode)) + frange_nextafter (mode, prev, ninf); + r.set (type, ninf, prev); return true; } @@ -424,9 +432,16 @@ build_gt (frange &r, tree type, const frange &val) return false; } - // We only support closed intervals. REAL_VALUE_TYPE inf = frange_val_max (type); - r.set (type, val.lower_bound (), inf); + REAL_VALUE_TYPE next = val.lower_bound (); + machine_mode mode = TYPE_MODE (type); + // Default to the conservatively correct closed ranges for + // MODE_COMPOSITE_P, otherwise use nextafter. Note that for + // !HONOR_INFINITIES, nextafter will yield +INF, but frange::set() + // will crop the range appropriately. + if (!MODE_COMPOSITE_P (mode)) + frange_nextafter (mode, next, inf); + r.set (type, next, inf); return true; } -- 2.38.1