From patchwork Wed Sep 14 15:08:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1212 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp743122dyb; Wed, 14 Sep 2022 08:10:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR5wXnuME/GcH0ZkBjoOmDkN5jnvhMzATiOV8KdYXCmioDoZF9C6G6WGAIEOFDMu7TlgSSi0 X-Received: by 2002:a17:907:6285:b0:738:e862:a1b with SMTP id nd5-20020a170907628500b00738e8620a1bmr27079958ejc.70.1663168237788; Wed, 14 Sep 2022 08:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663168237; cv=none; d=google.com; s=arc-20160816; b=hW15OJT9zxewbnTZowX1sFoqX0X8QdrrMAzDK8ZRG5Gbo5ZcyZe1HacB//LPn1cakM H48apCqiLbssdmbgfhI6XLlBx7e0HJgn1ICDWGARR8DuPYPA6uFzlg3NsHZlLo/5dcvS x1aY3Y+nkpzVcyj9Z4E3v6DjNAUXryR/DcdUvEY6IBfdBmFfaE8/YQeFXmQYsVrod6QL Mx4sXCQB74JfD5vwFY94y6A63QTtVha9G+odXYaWelWImoEs+aktvIgZyEtHNV26IPzt MtLVUL31Uq2XC/FmrJcfADB3scHT3GmizD+v5VJt4Z6vJs9Dy2YayGgUZSa2DArVx0jv cGkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=AEqJJPrKWTOL4OidbbcUYvgjylvDuIyuZPzSFemQKSY=; b=J+pv54Pt8fUV4KNMaqAbCVtATDDSKLyzW8Ps/scppMTVh2nkoo9Acv/NniAAqIs8V7 4RVIQHevNaGWu9x0ziVejzOT/44WCnoSqqyyExuKSlYVDxpIj2hpIfl3JsDPdkdSoCUd FSnEFpDgxCHgB8wvb/TK5nKwPpSAuSoRwGnFwEF53HukYGGA79MIrSBbb89LaX4ZszW5 X7dJtx7nG2LWOgQXelyDDFeXumVo1eX8DmtxwMAZ1OqYxM1KIAVtk5H2IKk07cn8u2Xb 36qMKP3BRDKj2uGoPSPBQb0IZVCp+XYyeRA5jjpLxjS76oJuOGR5JKKxikzcE7X125vI ixDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h6gagom1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i22-20020a1709064fd600b00771396445b2si8460955ejw.194.2022.09.14.08.10.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 08:10:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h6gagom1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00B9D383A202 for ; Wed, 14 Sep 2022 15:09:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00B9D383A202 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663168186; bh=AEqJJPrKWTOL4OidbbcUYvgjylvDuIyuZPzSFemQKSY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=h6gagom1Ln2EwJDJIV6+vT5pbNjVYtz2q7RrXhHQuzgjA+vXEtnGkWKIjzyHnuRJW 9lQjlPT5KOR1yk8WBTk2d9VaOMtt1S82Km1spZt4VHdBukc9JpDZRUhP9fBlZn7Vdw jMi7GwSTVNEOFFVdLR5eWvlUkRovu508C9RT0E5o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 To: GCC patches 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743958298203671901?= X-GMAIL-MSGID: =?utf-8?q?1743958298203671901?= 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;