From patchwork Tue Dec 19 17:21:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 181130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2094454dyi; Tue, 19 Dec 2023 09:22:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFz+qGSgbioTIbb1rtVVkatzg2RyBOJ9zPjdVXZPqtgFOauU0Od7Mx3yFD4rnAhtj2fB5IY X-Received: by 2002:a05:620a:272a:b0:77f:d39:ea3c with SMTP id b42-20020a05620a272a00b0077f0d39ea3cmr22851504qkp.87.1703006554114; Tue, 19 Dec 2023 09:22:34 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1703006554; cv=pass; d=google.com; s=arc-20160816; b=mk2DISxIJ0ZfC0pnLXS9/UDNdHMU60jNUs8+VvZgGvw0aIYFRDT8KIpSkC3kKQzbWZ itq74iVDCXUI4ycR4K5AxoT6erZQBlOg7+0t92dd92BTd2tBk8rtk3Uhfkxk94eDx6RW c6W1D6im+f0YrRUfQirIFuZxTNh/25UxT2qdPf6Spl5EJ9pY2f82VIHESvxE69gEZZ4C VeZLQVDuAWFwLnqTtq+igyimLA3sYsZkjTVAqT8XKu2MN9qo05XHHD0URWUOq0sohn1o GWGhvOPhYve6bTzciqfXz2kReITEW0HEVsJiQP9CZy91+FNsyiw0UCWPfb+sEkqeOH5e aVjQ== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=3/gCLfr19olyqHHtNiy8Rw+Gbgogiobxc299qj+CLnk=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=Dxo5HLuRVkq1VScRuWI41fr6Tl2vmSBZUwQw82EC9HqMi9lSdq8UveWbhgWhLbVrPw pm3rHRLqbMtbIPaO0tzV8yaOy6QU4tFph3bAgUqSI4werFa2ZkfuS1wQwWThGe/Sc7De XLgAxSNst46ug8yTs8H1TvDAZhOS2Bl7UPb6qLuzCoc1C9L87dYNtK/yaV1z4a2DGJ0l wqkRLrm2lQEaKKe1TfHC4UEb3Uy0swdal1XGAVHytO4tTVWYKYb3aWaxNanYYu3ZEmIP WaPC2m3Vla+RQmKhUhv4WoJtNDTDllSG6uD51JDQ1qe+ppECFJ5xOP2fhrsuVGVAbYTX dfbQ== ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@gotplt.org header.s=dreamhost header.b=A2jLvt2g; arc=pass (i=2); 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dw28-20020a05620a601c00b0077592c3366esi27348588qkb.329.2023.12.19.09.22.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 09:22:34 -0800 (PST) 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=@gotplt.org header.s=dreamhost header.b=A2jLvt2g; arc=pass (i=2); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF4F8385DC33 for ; Tue, 19 Dec 2023 17:22:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from sienna.cherry.relay.mailchannels.net (sienna.cherry.relay.mailchannels.net [23.83.223.165]) by sourceware.org (Postfix) with ESMTPS id D07203858417 for ; Tue, 19 Dec 2023 17:22:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D07203858417 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D07203858417 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.223.165 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1703006531; cv=pass; b=hGB/rrZIEMns3a6l0HEAzzuJqGc64loRf9YIS+/snIAKyNoqvtS1N10uV0z4y6nM3Io1LA3Gi9o+vO802f1tI1TSAbdCq+xmBYXXDMXtuyNud0n/TJD+ssozMgm4HGoInhGEpXFHy5djPrnVH3XcHfoDM8V86ObiLjNwbO+NOjE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1703006531; c=relaxed/simple; bh=B2B4WoLGdIX5APbnCYurPC3i6Lk29iqPr+BLKW2kF7I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sfd4k+MzA4DmW735qR4/VZ+8p40BpTD/QVmkvOZqoMmMIoJKYWhBnOxlqW29v4zkOyzuv95feBRHp+LPSfnI/BNEmKCvbBDZ7tKvVrItGZrGiZydIt3A0NI5nTNWYnrubFEQp5kczAxxy4vqSRxonkyUGAJZr/6gWYNRONSvjW8= ARC-Authentication-Results: i=2; server2.sourceware.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 77485902F5F for ; Tue, 19 Dec 2023 17:22:06 +0000 (UTC) Received: from pdx1-sub0-mail-a288.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 0F18F902F7A for ; Tue, 19 Dec 2023 17:22:06 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1703006526; a=rsa-sha256; cv=none; b=Q7rgHha/wKJZD2n3/P2w9xL8XGbIc4ZBoasqCSEhh+OGKCt1LKlQ0lkN7bpXJY4IYd5REx nLAiLyRC2xbEvuD1La3rt6JCYITlJ43ACPwm4qcZjt5q6I0MmprJh/UN8D9BLl/pmIa8uV i6EemrB5vvcXGedu8m92Dk0fo5ytGdPlb20BitnVQ4XSTt4rb+/xplZCTQ251cFZk0oVjt 0dnjvKfJCvJebSUUsAVKeOyYHROM8RI3ySXP/csWlQgxTWUXhNw64bAUWxqObM7xyaxfk9 Jh30Fu5E3axZwZf1M7MqhLtvC1u2uqWsfeF0J/T7+qe7UiLvsDQTZixd4afmyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1703006526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=3/gCLfr19olyqHHtNiy8Rw+Gbgogiobxc299qj+CLnk=; b=sw5MVKsrH93HUgHgbzB52Tum1/+zhFN7u8SAvdVtoIK52MDoxWedCJFJhozCoRKGeRVwNo Nzgi4xxnth/iIJd+dZbe71sN3ep4RPp8VmtlnEtG4/QDQKl9EDJbDTqSsHHdNGnZa7WdiL jCAoci43suIqm3rqJufh2sdK66RFDVJk64S+NKj/H3sxa2QlLROw90DOtXV/4CnB312lZI SpBgob65Or5ytgP5XB+eJu3HV5Mz9rTs2jGcnUICR6RkO7SgsAeeTuIy5HW/MKID06CDFD J+B9cw59lv5oxP1H/W+gNhXpHm46x70poiM4X7GLo84Fsm3IJbQqYnhP7H++jg== ARC-Authentication-Results: i=1; rspamd-659dcc87c8-jfhgx; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Whispering-Tart: 734630d45534b92c_1703006526309_2734572444 X-MC-Loop-Signature: 1703006526309:1151276457 X-MC-Ingress-Time: 1703006526308 Received: from pdx1-sub0-mail-a288.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.104.199.175 (trex/6.9.2); Tue, 19 Dec 2023 17:22:06 +0000 Received: from fedora.redhat.com (bras-vprn-toroon4834w-lp130-02-142-113-138-136.dsl.bell.ca [142.113.138.136]) (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) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a288.dreamhost.com (Postfix) with ESMTPSA id 4Svk5T479vzlY for ; Tue, 19 Dec 2023 09:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1703006525; bh=3/gCLfr19olyqHHtNiy8Rw+Gbgogiobxc299qj+CLnk=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=A2jLvt2gK+Siwwla4/d4azPhSgINeHbHdGxvMT0ESuV75aOZTsQXTUkC5vZcm8bFX gTFhY/P7hscMDdnK0oxXITgM1hMKvqMc+G2NSZyrrk+dMGYXhdOYdMgktR2gvkYYeU I2IIU+ESpG8KWA4ElB+mPd+hp52SGt/kiZmuwSmhknFLNj/qdyffer7sBhMtPfDeYJ gEunxmCh/4pThZMgrmxQVG864mVcH3hlcOuX76zrsPhavSB0G+xKrgY/uIPPnLt5lB WDOh8KOYuKjUR1EJb5taabGxjhC8VihJSaYbArpQUS/oWysmvAZIRTcXCh7l64S80n 0J0VI/kILtyFg== From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-object-size: Clean up unknown propagation Date: Tue, 19 Dec 2023 12:21:53 -0500 Message-ID: <20231219172153.2298161-1-siddhesh@gotplt.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3036.2 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785731800172010595 X-GMAIL-MSGID: 1785731800172010595 Narrow down scope of the unknowns bitmap so that it is only accessible within the reexamination process. This also removes any role of unknown propagation from object_sizes_set, thus simplifying that code path a bit. gcc/ChangeLog: * tree-object-size.cc (object_size_info): Remove UNKNOWNS. Drop all references to it. (object_sizes_set): Move unknowns propagation code to... (gimplify_size_expressions): ... here. Also free reexamine bitmap. (propagate_unknowns): New parameter UNKNOWNS. Update callers. Signed-off-by: Siddhesh Poyarekar --- This is a follow-up cleanup to pr#113012, but not required to fix that bug. Bootstrapped on x86_64 and with config=ubsan. gcc/tree-object-size.cc | 65 +++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 434b2fc0bf5..08a3b7f5d94 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -43,7 +43,7 @@ struct object_size_info int object_size_type; unsigned char pass; bool changed; - bitmap visited, reexamine, unknowns; + bitmap visited, reexamine; unsigned int *depths; unsigned int *stack, *tos; }; @@ -264,19 +264,8 @@ object_sizes_set (struct object_size_info *osi, unsigned varno, tree val, { if (bitmap_bit_p (osi->reexamine, varno)) { - if (size_unknown_p (val, object_size_type)) - { - oldval = object_sizes_get (osi, varno); - old_wholeval = object_sizes_get (osi, varno, true); - bitmap_set_bit (osi->unknowns, SSA_NAME_VERSION (oldval)); - bitmap_set_bit (osi->unknowns, SSA_NAME_VERSION (old_wholeval)); - bitmap_clear_bit (osi->reexamine, varno); - } - else - { - val = bundle_sizes (oldval, val); - wholeval = bundle_sizes (old_wholeval, wholeval); - } + val = bundle_sizes (oldval, val); + wholeval = bundle_sizes (old_wholeval, wholeval); } else { @@ -958,25 +947,26 @@ emit_phi_nodes (gimple *stmt, tree size, tree wholesize) size_unknown, as noted in UNKNOWNS. */ static tree -propagate_unknowns (object_size_info *osi, tree expr) +propagate_unknowns (object_size_info *osi, tree expr, bitmap unknowns) { int object_size_type = osi->object_size_type; switch (TREE_CODE (expr)) { case SSA_NAME: - if (bitmap_bit_p (osi->unknowns, SSA_NAME_VERSION (expr))) + if (bitmap_bit_p (unknowns, SSA_NAME_VERSION (expr))) return size_unknown (object_size_type); return expr; case MIN_EXPR: case MAX_EXPR: { - tree res = propagate_unknowns (osi, TREE_OPERAND (expr, 0)); + tree res = propagate_unknowns (osi, TREE_OPERAND (expr, 0), + unknowns); if (size_unknown_p (res, object_size_type)) return res; - res = propagate_unknowns (osi, TREE_OPERAND (expr, 1)); + res = propagate_unknowns (osi, TREE_OPERAND (expr, 1), unknowns); if (size_unknown_p (res, object_size_type)) return res; @@ -984,7 +974,8 @@ propagate_unknowns (object_size_info *osi, tree expr) } case MODIFY_EXPR: { - tree res = propagate_unknowns (osi, TREE_OPERAND (expr, 1)); + tree res = propagate_unknowns (osi, TREE_OPERAND (expr, 1), + unknowns); if (size_unknown_p (res, object_size_type)) return res; return expr; @@ -992,7 +983,8 @@ propagate_unknowns (object_size_info *osi, tree expr) case TREE_VEC: for (int i = 0; i < TREE_VEC_LENGTH (expr); i++) { - tree res = propagate_unknowns (osi, TREE_VEC_ELT (expr, i)); + tree res = propagate_unknowns (osi, TREE_VEC_ELT (expr, i), + unknowns); if (size_unknown_p (res, object_size_type)) return res; } @@ -1000,7 +992,8 @@ propagate_unknowns (object_size_info *osi, tree expr) case PLUS_EXPR: case MINUS_EXPR: { - tree res = propagate_unknowns (osi, TREE_OPERAND (expr, 0)); + tree res = propagate_unknowns (osi, TREE_OPERAND (expr, 0), + unknowns); if (size_unknown_p (res, object_size_type)) return res; @@ -1025,6 +1018,7 @@ gimplify_size_expressions (object_size_info *osi) /* Step 1: Propagate unknowns into expressions. */ bitmap reexamine = BITMAP_ALLOC (NULL); bitmap_copy (reexamine, osi->reexamine); + bitmap unknowns = BITMAP_ALLOC (NULL); do { changed = false; @@ -1032,14 +1026,23 @@ gimplify_size_expressions (object_size_info *osi) { object_size cur = object_sizes_get_raw (osi, i); - if (size_unknown_p (propagate_unknowns (osi, cur.size), + if (size_unknown_p (propagate_unknowns (osi, cur.size, unknowns), object_size_type) - || size_unknown_p (propagate_unknowns (osi, cur.wholesize), + || size_unknown_p (propagate_unknowns (osi, cur.wholesize, + unknowns), object_size_type)) { - object_sizes_set (osi, i, - size_unknown (object_size_type), - size_unknown (object_size_type)); + /* Record the SSAs we're overwriting to propagate the + unknwons. */ + tree oldval = object_sizes_get (osi, i); + tree old_wholeval = object_sizes_get (osi, i, true); + + bitmap_set_bit (unknowns, SSA_NAME_VERSION (oldval)); + bitmap_set_bit (unknowns, SSA_NAME_VERSION (old_wholeval)); + object_sizes_initialize (osi, i, + size_unknown (object_size_type), + size_unknown (object_size_type)); + bitmap_clear_bit (osi->reexamine, i); changed = true; } } @@ -1048,9 +1051,12 @@ gimplify_size_expressions (object_size_info *osi) while (changed); /* Release all unknowns. */ - EXECUTE_IF_SET_IN_BITMAP (osi->unknowns, 0, i, bi) + EXECUTE_IF_SET_IN_BITMAP (unknowns, 0, i, bi) release_ssa_name (ssa_name (i)); + BITMAP_FREE (unknowns); + BITMAP_FREE (reexamine); + /* Expand all size expressions to put their definitions close to the objects for which size is being computed. */ EXECUTE_IF_SET_IN_BITMAP (osi->reexamine, 0, i, bi) @@ -1176,9 +1182,7 @@ compute_builtin_object_size (tree ptr, int object_size_type, osi.visited = BITMAP_ALLOC (NULL); osi.reexamine = BITMAP_ALLOC (NULL); - if (object_size_type & OST_DYNAMIC) - osi.unknowns = BITMAP_ALLOC (NULL); - else + if (!(object_size_type & OST_DYNAMIC)) { osi.depths = NULL; osi.stack = NULL; @@ -1199,7 +1203,6 @@ compute_builtin_object_size (tree ptr, int object_size_type, { osi.pass = 1; gimplify_size_expressions (&osi); - BITMAP_FREE (osi.unknowns); bitmap_clear (osi.reexamine); }