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 7B42C3858286 for ; Wed, 14 Sep 2022 15:09:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B42C3858286 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=1663168142; 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=AEqJJPrKWTOL4OidbbcUYvgjylvDuIyuZPzSFemQKSY=; b=YWImm7HG8gQIp4+QhVi/ZvKkF6djr+j/8JGGtcL7Pm4Mjhf0YF31Kpbdv2mznu8rjxwFGL NGRjNhhU/wGv6xJ+lVYn8BWSmoNnUDEIQJLacpgZcEnR4e6k47nle4WTjTtDZEziF1yXS2 QvumDPlEAX59zVLkUGbWT3Y2KTGLqzE= 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-550-J8GJVCkUMFiFG4RRYx597w-1; Wed, 14 Sep 2022 11:09:01 -0400 X-MC-Unique: J8GJVCkUMFiFG4RRYx597w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B211B85A583 for ; Wed, 14 Sep 2022 15:09:00 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.40.192.189]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BF3E4B3FC6; Wed, 14 Sep 2022 15:09:00 +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 28EF8wLN1244461 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 17:08:58 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28EF8w6k1244460; Wed, 14 Sep 2022 17:08:58 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] frange: add both zeros to ranges when there's the possiblity of equality. Date: Wed, 14 Sep 2022 17:08:52 +0200 Message-Id: <20220914150852.1244397-5-aldyh@redhat.com> In-Reply-To: <20220914150852.1244397-1-aldyh@redhat.com> References: <20220914150852.1244397-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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.8 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,SPF_HELO_NONE,SPF_NONE,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: Every time there's equality at play, we must be careful that any equality with zero matches both -0.0 and +0.0 when honoring signed zeros. We were doing this correctly for the == and != op1_range operators (albeit inefficiently), but aren't doing it at all when building >= and <=. This fixes the oversight. There is change in functionality here for the build_* functions. This is the last "simple" patch I submit before overhauling NAN and sign tracking. And that will likely be after Cauldron because it will need further testing (lapack, ppc64le, -ffinite-math-only, etc). Regstrapped on x86-64 Linux, plus I ran selftests for -ffinite-math-only. gcc/ChangeLog: * range-op-float.cc (frange_add_zeros): New. (build_le): Call frange_add_zeros. (build_ge): Same. (foperator_equal::op1_range): Same. (foperator_not_equal::op1_range): Same. --- gcc/range-op-float.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 8f3e5241313..fbc14a730ad 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -208,6 +208,19 @@ frange_drop_ninf (frange &r, tree type) r.intersect (tmp); } +// If zero is in R, make sure both -0.0 and +0.0 are in the range. + +static inline void +frange_add_zeros (frange &r, tree type) +{ + if (r.undefined_p () || r.known_nan ()) + return; + + if (HONOR_SIGNED_ZEROS (type) + && (real_iszero (&r.lower_bound ()) || real_iszero (&r.upper_bound ()))) + r.set_signbit (fp_prop::VARYING); +} + // Build a range that is <= VAL and store it in R. static bool @@ -219,6 +232,10 @@ build_le (frange &r, tree type, const frange &val) return false; } r.set (type, dconstninf, val.upper_bound ()); + + // Add both zeros if there's the possibility of zero equality. + frange_add_zeros (r, type); + return true; } @@ -257,6 +274,10 @@ build_ge (frange &r, tree type, const frange &val) return false; } r.set (type, val.lower_bound (), dconstinf); + + // Add both zeros if there's the possibility of zero equality. + frange_add_zeros (r, type); + return true; } @@ -376,9 +397,8 @@ foperator_equal::op1_range (frange &r, tree type, case BRS_TRUE: // If it's true, the result is the same as OP2. r = op2; - // Make sure we don't copy the sign bit if we may have a zero. - if (HONOR_SIGNED_ZEROS (type) && r.contains_p (build_zero_cst (type))) - r.set_signbit (fp_prop::VARYING); + // Add both zeros if there's the possibility of zero equality. + frange_add_zeros (r, type); // The TRUE side of op1 == op2 implies op1 is !NAN. r.clear_nan (); break; @@ -480,9 +500,8 @@ foperator_not_equal::op1_range (frange &r, tree type, case BRS_FALSE: // If it's false, the result is the same as OP2. r = op2; - // Make sure we don't copy the sign bit if we may have a zero. - if (HONOR_SIGNED_ZEROS (type) && r.contains_p (build_zero_cst (type))) - r.set_signbit (fp_prop::VARYING); + // Add both zeros if there's the possibility of zero equality. + frange_add_zeros (r, type); // The FALSE side of op1 != op2 implies op1 is !NAN. r.clear_nan (); break; -- 2.37.1