From patchwork Thu Sep 7 22:12:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1831162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tt/Ijejx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RhYQL5fqbz1ygR for ; Fri, 8 Sep 2023 08:12:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DC523858D20 for ; Thu, 7 Sep 2023 22:12:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DC523858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694124759; bh=Bj6VUXIBxd2xejDvQAQI+2FPIFb7D32X3h8Psy5Aajc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tt/IjejxGcNihHB2O95WAykYoKyPz8FIsydPdfyorT4XOKkc7HJ0cQUCsU4gS+ByR yjDk0Bp3WrzichCVX4TRj59k77oZXzcJyf7Miz59m3L4MXsF5yzoA7KSxLqlPIBD9h yb6qH/CK/Rqr1qQ49S1e42uhY9OH/Tsdrad4dIYk= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id C914D3858D1E for ; Thu, 7 Sep 2023 22:12:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C914D3858D1E 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-393-7S_eSGYlP4-2QL4XHpSWLw-1; Thu, 07 Sep 2023 18:12:17 -0400 X-MC-Unique: 7S_eSGYlP4-2QL4XHpSWLw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D63888001EA for ; Thu, 7 Sep 2023 22:12:16 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.22.8.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B856A7B62; Thu, 7 Sep 2023 22:12:16 +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 387MCFOR103651 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Sep 2023 18:12:16 -0400 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 387MCFUD103650; Thu, 7 Sep 2023 18:12:15 -0400 To: GCC patches Subject: [COMMITTED] [irange] Fix typo in contains_zero_p. Date: Thu, 7 Sep 2023 18:12:06 -0400 Message-ID: <20230907221213.103635-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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_H4, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In the conversion of iranges to wide_int (commit cb779afeff204f), I mistakenly made contains_zero_p() return TRUE for undefined ranges. This means the rest of the patch was adjusted for this stupidity. For example, we ended up doing the following, to make up for the fact that contains_zero_p was broken: - if (!lhs.contains_p (build_zero_cst (lhs.type ()))) + if (lhs.undefined_p () || !contains_zero_p (lhs)) This patch fixes the thinko and adjusts all callers. In places where a caller is not checking undefined_p(), it is because either the caller has already handled undefined ranges in the preceeding code, or the check is superfluous. gcc/ChangeLog: * value-range.h (contains_zero_p): Return false for undefined ranges. * range-op-float.cc (operator_gt::op1_op2_relation): Adjust for contains_zero_p change above. (operator_ge::op1_op2_relation): Same. * range-op.cc (operator_equal::op1_op2_relation): Same. (operator_not_equal::op1_op2_relation): Same. (operator_lt::op1_op2_relation): Same. (operator_le::op1_op2_relation): Same. (operator_cast::op1_range): Same. (set_nonzero_range_from_mask): Same. (operator_bitwise_xor::op1_range): Same. (operator_addr_expr::fold_range): Same. (operator_addr_expr::op1_range): Same. * range-op-float.cc (operator_equal::op1_op2_relation): Same. (operator_not_equal::op1_op2_relation): Same. (operator_lt::op1_op2_relation): Same. (operator_le::op1_op2_relation): Same. (operator_gt::op1_op2_relation): Same. (operator_ge::op1_op2_relation): Same. --- gcc/range-op-float.cc | 8 ++++---- gcc/range-op.cc | 30 +++++++++++++++--------------- gcc/value-range.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index eebc73f9918..89c401e040a 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -783,7 +783,7 @@ operator_equal::op1_op2_relation (const irange &lhs, const frange &, return VREL_NE; // TRUE = op1 == op2 indicates EQ_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_EQ; return VREL_VARYING; } @@ -915,7 +915,7 @@ operator_not_equal::op1_op2_relation (const irange &lhs, const frange &, return VREL_EQ; // TRUE = op1 != op2 indicates NE_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_NE; return VREL_VARYING; } @@ -1037,7 +1037,7 @@ operator_lt::op1_op2_relation (const irange &lhs, const frange &, return VREL_GE; // TRUE = op1 < op2 indicates LT_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_LT; return VREL_VARYING; } @@ -1144,7 +1144,7 @@ operator_le::op1_op2_relation (const irange &lhs, const frange &, return VREL_GT; // TRUE = op1 <= op2 indicates LE_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_LE; return VREL_VARYING; } diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 619979f2f61..33b193be7d0 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -915,7 +915,7 @@ operator_equal::op1_op2_relation (const irange &lhs, const irange &, return VREL_NE; // TRUE = op1 == op2 indicates EQ_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_EQ; return VREL_VARYING; } @@ -1017,7 +1017,7 @@ operator_not_equal::op1_op2_relation (const irange &lhs, const irange &, return VREL_EQ; // TRUE = op1 != op2 indicates NE_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_NE; return VREL_VARYING; } @@ -1178,7 +1178,7 @@ operator_lt::op1_op2_relation (const irange &lhs, const irange &, return VREL_GE; // TRUE = op1 < op2 indicates LT_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_LT; return VREL_VARYING; } @@ -1279,7 +1279,7 @@ operator_le::op1_op2_relation (const irange &lhs, const irange &, return VREL_GT; // TRUE = op1 <= op2 indicates LE_EXPR. - if (lhs.undefined_p () || !contains_zero_p (lhs)) + if (!contains_zero_p (lhs)) return VREL_LE; return VREL_VARYING; } @@ -2957,7 +2957,7 @@ operator_cast::op1_range (irange &r, tree type, { // If the LHS is not a pointer nor a singleton, then it is // either VARYING or non-zero. - if (!contains_zero_p (lhs)) + if (!lhs.undefined_p () && !contains_zero_p (lhs)) r.set_nonzero (type); else r.set_varying (type); @@ -3368,10 +3368,10 @@ operator_bitwise_and::wi_fold (irange &r, tree type, static void set_nonzero_range_from_mask (irange &r, tree type, const irange &lhs) { - if (!contains_zero_p (lhs)) - r = range_nonzero (type); - else + if (lhs.undefined_p () || contains_zero_p (lhs)) r.set_varying (type); + else + r.set_nonzero (type); } /* Find out smallest RES where RES > VAL && (RES & MASK) == RES, if any @@ -3798,7 +3798,7 @@ operator_bitwise_xor::op1_range (irange &r, tree type, else if (op2.zero_p ()) r = range_true (type); // See get_bool_state for the rationale - else if (contains_zero_p (op2)) + else if (op2.undefined_p () || contains_zero_p (op2)) r = range_true_and_false (type); else r = range_false (type); @@ -4335,10 +4335,10 @@ operator_addr_expr::fold_range (irange &r, tree type, // Return a non-null pointer of the LHS type (passed in op2). if (lh.zero_p ()) r = range_zero (type); - else if (!contains_zero_p (lh)) - r = range_nonzero (type); - else + else if (lh.undefined_p () || contains_zero_p (lh)) r.set_varying (type); + else + r.set_nonzero (type); return true; } @@ -4348,14 +4348,14 @@ operator_addr_expr::op1_range (irange &r, tree type, const irange &op2, relation_trio) const { - if (empty_range_varying (r, type, lhs, op2)) + if (empty_range_varying (r, type, lhs, op2)) return true; // Return a non-null pointer of the LHS type (passed in op2), but only // if we cant overflow, eitherwise a no-zero offset could wrap to zero. // See PR 111009. - if (!contains_zero_p (lhs) && TYPE_OVERFLOW_UNDEFINED (type)) - r = range_nonzero (type); + if (!lhs.undefined_p () && !contains_zero_p (lhs) && TYPE_OVERFLOW_UNDEFINED (type)) + r.set_nonzero (type); else r.set_varying (type); return true; diff --git a/gcc/value-range.h b/gcc/value-range.h index 6c5be36d74d..da04be00ab4 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -1158,7 +1158,7 @@ inline bool contains_zero_p (const irange &r) { if (r.undefined_p ()) - return true; + return false; wide_int zero = wi::zero (TYPE_PRECISION (r.type ())); return r.contains_p (zero);