From patchwork Fri Dec 17 21:42:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1570382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gotplt.org header.i=@gotplt.org header.a=rsa-sha1 header.s=gotplt.org header.b=vcSnywS7; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JG2XX580rz9sRR for ; Sat, 18 Dec 2021 08:43:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 289263858430 for ; Fri, 17 Dec 2021 21:43:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from bumble.birch.relay.mailchannels.net (bumble.birch.relay.mailchannels.net [23.83.209.25]) by sourceware.org (Postfix) with ESMTPS id BFBE33858407 for ; Fri, 17 Dec 2021 21:42:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BFBE33858407 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 30892881026; Fri, 17 Dec 2021 21:42:50 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 41C7E881060; Fri, 17 Dec 2021 21:42:49 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.81.136 (trex/6.4.3); Fri, 17 Dec 2021 21:42:50 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Lyrical-Cold: 33d4bfdc290dcb1f_1639777369976_4113494662 X-MC-Loop-Signature: 1639777369976:3522582627 X-MC-Ingress-Time: 1639777369976 Received: from rhbox.redhat.com (unknown [1.6.40.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4JG2X73n34z2Y; Fri, 17 Dec 2021 13:42:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gotplt.org; s=gotplt.org; t=1639777369; bh=qGEdli3Rhc1Hk9pt9MAZvFSVJh0=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=vcSnywS7vgo2bNglK/4yvPxDaVxuHcTZhzMEy4SvmSvvyRiOCD5Q9RVKiKNsn5PpR 1R8YQXRw7Su90d+VIzJflIMrsO2PyeRHG+QgWOZhPdF6LO8WeNHL6YKefTLFrvpeoX 04bUioS16ZBGDcjSz6ZU/QOUA0lYrAqVuKSyp7DM= From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] tree-optimization/103759: Truncate unknown to sizetype on compare Date: Sat, 18 Dec 2021 03:12:36 +0530 Message-Id: <20211217214236.87965-1-siddhesh@gotplt.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00, 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: jakub@redhat.com, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Since all computations in tree-object-size are now done in sizetype and not HOST_WIDE_INT, comparisons after conversion to HOST_WIDE_INT would be incorrect. Instead, truncate unknown (object_size_type) to sizetype to compare with the computed size to evaluate if it is unknown. gcc/ChangeLog: PR tree-optimization/103759 * tree-object-size (unknown, initval): Change to arrays. Adjust all uses. (init_limits): Rename from init_offset_limit. Initialize UNKNOWN and INITVAL. Adjust all uses. Signed-off-by: Siddhesh Poyarekar --- Changes from v1: Alternative approach that doesn't result in unnecessary construction of trees. gcc/tree-object-size.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index 71f6b747d05..fc5f82e7c36 100644 --- a/gcc/tree-object-size.c +++ b/gcc/tree-object-size.c @@ -64,7 +64,7 @@ static void expr_object_size (struct object_size_info *, tree, tree); static bool merge_object_sizes (struct object_size_info *, tree, tree); static bool plus_stmt_object_size (struct object_size_info *, tree, gimple *); static bool cond_expr_object_size (struct object_size_info *, tree, gimple *); -static void init_offset_limit (void); +static void init_limits (void); static void check_for_plus_in_loops (struct object_size_info *, tree); static void check_for_plus_in_loops_1 (struct object_size_info *, tree, unsigned int); @@ -85,20 +85,10 @@ static unsigned HOST_WIDE_INT offset_limit; /* Initial value of object sizes; zero for maximum and SIZE_MAX for minimum object size. */ - -static inline unsigned HOST_WIDE_INT -initval (int object_size_type) -{ - return (object_size_type & OST_MINIMUM) ? HOST_WIDE_INT_M1U : 0; -} +static unsigned HOST_WIDE_INT initval[OST_END]; /* Unknown object size value; it's the opposite of initval. */ - -static inline unsigned HOST_WIDE_INT -unknown (int object_size_type) -{ - return ~initval (object_size_type); -} +static unsigned HOST_WIDE_INT unknown[OST_END]; /* Return true if VAL is represents an unknown size for OBJECT_SIZE_TYPE. */ @@ -106,7 +96,7 @@ static inline bool size_unknown_p (tree val, int object_size_type) { return (tree_fits_uhwi_p (val) - && tree_to_uhwi (val) == unknown (object_size_type)); + && tree_to_uhwi (val) == unknown[object_size_type]); } /* Return a tree with initial value for OBJECT_SIZE_TYPE. */ @@ -114,7 +104,7 @@ size_unknown_p (tree val, int object_size_type) static inline tree size_initval (int object_size_type) { - return size_int (initval (object_size_type)); + return size_int (initval[object_size_type]); } /* Return a tree with unknown value for OBJECT_SIZE_TYPE. */ @@ -122,7 +112,7 @@ size_initval (int object_size_type) static inline tree size_unknown (int object_size_type) { - return size_int (unknown (object_size_type)); + return size_int (unknown[object_size_type]); } /* Grow object_sizes[OBJECT_SIZE_TYPE] to num_ssa_names. */ @@ -202,13 +192,21 @@ object_sizes_set (struct object_size_info *osi, unsigned varno, tree val, /* Initialize OFFSET_LIMIT variable. */ static void -init_offset_limit (void) +init_limits (void) { if (tree_fits_uhwi_p (TYPE_MAX_VALUE (sizetype))) offset_limit = tree_to_uhwi (TYPE_MAX_VALUE (sizetype)); else offset_limit = -1; offset_limit /= 2; + + for (int i = 0; i < OST_END; i++) + { + if (i & OST_MINIMUM) + initval[i] = tree_to_uhwi (size_int (HOST_WIDE_INT_M1U)); + else + unknown[i] = tree_to_uhwi (size_int (HOST_WIDE_INT_M1U)); + } } /* Bytes at end of the object with SZ from offset OFFSET. If WHOLESIZE is not @@ -705,7 +703,7 @@ compute_builtin_object_size (tree ptr, int object_size_type, *psize = size_unknown (object_size_type); if (! offset_limit) - init_offset_limit (); + init_limits (); if (TREE_CODE (ptr) == ADDR_EXPR) return addr_object_size (NULL, ptr, object_size_type, psize); @@ -1374,7 +1372,7 @@ init_object_sizes (void) computed[object_size_type] = BITMAP_ALLOC (NULL); } - init_offset_limit (); + init_limits (); }