From patchwork Wed Apr 26 11:47:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1774057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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=OUPSsff2; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q5xvv3B8Yz23vJ for ; Wed, 26 Apr 2023 21:48:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D68BB3857024 for ; Wed, 26 Apr 2023 11:48:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D68BB3857024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682509701; bh=UAdw8MfVR/t0BKPouy93+Oogc/NdcAMabcFKpkDxkJ4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=OUPSsff24Ga4pjOmHdq5L97NV43hJ3kN0ynObxDQknnG9lUzmV06HiQRtk0sMKU2o TgxSgS+mMMBpxlKdDN3fjoMHhhq2LMkTPQnD5U904cxgg64n0jE9nq6hWG2S/Zn+ic GBDJR9PbktDD/XqVD/SXCgo0WmPgIa9h/ft5D5LM= 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 238BB3858C54 for ; Wed, 26 Apr 2023 11:48:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 238BB3858C54 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-284-jok9Pd7TPJWCfIs3gqqIhg-1; Wed, 26 Apr 2023 07:47:58 -0400 X-MC-Unique: jok9Pd7TPJWCfIs3gqqIhg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F5EC87A9EC for ; Wed, 26 Apr 2023 11:47:58 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7EA340C6E67; Wed, 26 Apr 2023 11:47:57 +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 33QBlutK336954 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 13:47:56 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 33QBlueP336953; Wed, 26 Apr 2023 13:47:56 +0200 To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] Fix swapping of ranges. Date: Wed, 26 Apr 2023 13:47:46 +0200 Message-Id: <20230426114752.336928-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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_H2, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The legacy range code has logic to swap out of order endpoints in the irange constructor. The new irange code expects the caller to fix any inconsistencies, thus speeding up the common case. However, this means that when we remove legacy, any stragglers must be fixed. This patch fixes the 3 culprits found during the conversion. gcc/ChangeLog: * range-op.cc (operator_cast::op1_range): Use create_possibly_reversed_range. (operator_bitwise_and::simple_op1_range_solver): Same. * value-range.cc (swap_out_of_order_endpoints): Delete. (irange::set): Remove call to swap_out_of_order_endpoints. --- gcc/range-op.cc | 10 ++++++---- gcc/value-range.cc | 47 ---------------------------------------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index f90e78dcfbc..e47edcf3d74 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2876,8 +2876,9 @@ operator_cast::op1_range (irange &r, tree type, // Start by building the positive signed outer range for the type. wide_int lim = wi::set_bit_in_zero (TYPE_PRECISION (lhs_type), TYPE_PRECISION (type)); - r = int_range<1> (type, lim, wi::max_value (TYPE_PRECISION (type), - SIGNED)); + create_possibly_reversed_range (r, type, lim, + wi::max_value (TYPE_PRECISION (type), + SIGNED)); // For the signed part, we need to simply union the 2 ranges now. r.union_ (converted_lhs); @@ -3367,7 +3368,7 @@ operator_bitwise_and::simple_op1_range_solver (irange &r, tree type, if (we_know_nothing) r.set_varying (type); else - r = int_range<1> (type, minv, maxv); + create_possibly_reversed_range (r, type, minv, maxv); // Solve [-INF, lhs.upper_bound ()] = x & MASK. // @@ -3398,7 +3399,8 @@ operator_bitwise_and::simple_op1_range_solver (irange &r, tree type, } maxv |= ~cst2v; minv = sgnbit; - int_range<1> upper_bits (type, minv, maxv); + int_range<2> upper_bits; + create_possibly_reversed_range (upper_bits, type, minv, maxv); r.intersect (upper_bits); } diff --git a/gcc/value-range.cc b/gcc/value-range.cc index a50d1a63968..da9098139ad 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -1014,46 +1014,6 @@ irange::copy_to_legacy (const irange &src) set (src.tree_lower_bound (), src.tree_upper_bound ()); } -// Swap MIN/MAX if they are out of order and adjust KIND appropriately. - -static void -swap_out_of_order_endpoints (tree &min, tree &max, value_range_kind &kind) -{ - gcc_checking_assert (kind != VR_UNDEFINED); - if (kind == VR_VARYING) - return; - /* Wrong order for min and max, to swap them and the VR type we need - to adjust them. */ - if (tree_int_cst_lt (max, min)) - { - tree one, tmp; - - /* For one bit precision if max < min, then the swapped - range covers all values, so for VR_RANGE it is varying and - for VR_ANTI_RANGE empty range, so drop to varying as well. */ - if (TYPE_PRECISION (TREE_TYPE (min)) == 1) - { - kind = VR_VARYING; - return; - } - - one = build_int_cst (TREE_TYPE (min), 1); - tmp = int_const_binop (PLUS_EXPR, max, one); - max = int_const_binop (MINUS_EXPR, min, one); - min = tmp; - - /* There's one corner case, if we had [C+1, C] before we now have - that again. But this represents an empty value range, so drop - to varying in this case. */ - if (tree_int_cst_lt (max, min)) - { - kind = VR_VARYING; - return; - } - kind = kind == VR_RANGE ? VR_ANTI_RANGE : VR_RANGE; - } -} - void irange::irange_set (tree min, tree max) { @@ -1192,13 +1152,6 @@ irange::set (tree min, tree max, value_range_kind kind) gcc_checking_assert (TREE_CODE (min) == INTEGER_CST && TREE_CODE (max) == INTEGER_CST); - swap_out_of_order_endpoints (min, max, kind); - if (kind == VR_VARYING) - { - set_varying (TREE_TYPE (min)); - return; - } - // Anti-ranges that can be represented as ranges should be so. if (kind == VR_ANTI_RANGE) {