From patchwork Fri May 10 07:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1933737 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NdqWBMG6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VbKbC2hGLz1ymg for ; Fri, 10 May 2024 17:03:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 770A33849AEA for ; Fri, 10 May 2024 07:02:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 1357E384CBA1 for ; Fri, 10 May 2024 07:02:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1357E384CBA1 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1357E384CBA1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715324560; cv=none; b=eMEqekZHnyK8kMMvviaLvyqm0Iy3RLP8/RifTJ870tWPfDX0u9tn2aA0Qfu8xE1CWtfnnTcr9OllSedd98Zd1WVPA6fS3WdeH+daLogkLRZVu3ZEngFkUdKky+YIYJw272imwTtdZT/i3obzNddZris9Cml91VObzW+05O/lRVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715324560; c=relaxed/simple; bh=PFxsBdFu9oCOCa5hJBLyy+TJhn2sVBBEAbzzqiEvVBE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JZWTq+6EQ66e27L9tlz3mDDUglgp3XOKtX9vfKK75SURg+3XaaNSt12yQo0B9A8IJ8V4Fp3Y0JERDvc0WqPNpxYK3g89qlE3r6jfwk/2gqGSRsN0RbStewjdYd9lob3wkTYhPHaQD8nY8nOPHV/ACyUEUWVbQ7p81bL04v1O+8Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715324549; 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=mlKotmYMqVuDRc9cQOBu4GOkkCG2EKHASyEyn3q/VtM=; b=NdqWBMG6ClTe+eHv3qGzMYINXq4aN5PvQjeQih8ahnDPSMndCnUp/xK0J2WHKMZm1VLiFe fQLgfqVzpoXEYIvJOjLAmUWZG3m3f/M61oJYOXgbo04r3SRlOrAAUBm5KQJYmP1jDje6qw 5iScMt3znmqP81ewazvs4m6Z/yZNPyg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-UiastxWDPqeWAyX5jSkNpg-1; Fri, 10 May 2024 03:02:27 -0400 X-MC-Unique: UiastxWDPqeWAyX5jSkNpg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DC72101A551 for ; Fri, 10 May 2024 07:02:27 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD5C22079B08; Fri, 10 May 2024 07:02:26 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 44A72PNI382517 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 10 May 2024 09:02:25 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 44A72Pbc382516; Fri, 10 May 2024 09:02:25 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [prange] Do not assume all pointers are the same size [PR115009] Date: Fri, 10 May 2024 09:02:09 +0200 Message-ID: <20240510070220.382491-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_LOW, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org In a world with same sized pointers we can always reuse the storage slots, but since this is not always the case, we need to be more careful. However, we can always store an undefined, because that requires no extra storage. gcc/ChangeLog: PR tree-optimization/115009 * value-range-storage.cc (prange_storage::alloc): Do not assume all pointers are the same size. (prange_storage::prange_storage): Same. (prange_storage::fits_p): Same. --- gcc/value-range-storage.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index bbae0da4772..8e8d61d5935 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -593,12 +593,12 @@ frange_storage::fits_p (const frange &) const prange_storage * prange_storage::alloc (vrange_internal_alloc &allocator, const prange &r) { - // Assume all pointers are the same size. - unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node)); - gcc_checking_assert (r.undefined_p () || TYPE_PRECISION (r.type ()) == prec); - - typedef trailing_wide_ints twi; - size_t size = sizeof (prange_storage) + twi::extra_size (prec); + size_t size = sizeof (prange_storage); + if (!r.undefined_p ()) + { + unsigned prec = TYPE_PRECISION (r.type ()); + size += trailing_wide_ints::extra_size (prec); + } prange_storage *p = static_cast (allocator.alloc (size)); new (p) prange_storage (r); return p; @@ -610,8 +610,12 @@ prange_storage::prange_storage (const prange &r) { // It is the caller's responsibility to allocate enough space such // that the precision fits. - unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node)); - m_trailing_ints.set_precision (prec); + if (r.undefined_p ()) + // Undefined ranges do not require any extra space for trailing + // wide ints. + m_trailing_ints.set_precision (0); + else + m_trailing_ints.set_precision (TYPE_PRECISION (r.type ())); set_prange (r); } @@ -669,10 +673,14 @@ prange_storage::equal_p (const prange &r) const } bool -prange_storage::fits_p (const prange &) const +prange_storage::fits_p (const prange &r) const { - // All pointers are the same size. - return true; + // Undefined ranges always fit, because they don't store anything in + // the trailing wide ints. + if (r.undefined_p ()) + return true; + + return TYPE_PRECISION (r.type ()) <= m_trailing_ints.get_precision (); }