{"id":2226270,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2226270/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhubeob5uw.gcc.gcc-TEST.pinskia.21.1.2@forge-stage.sourceware.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.2/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<bmm.hhubeob5uw.gcc.gcc-TEST.pinskia.21.1.2@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T10:31:25","name":"[v1,2/4] cfgexpand: Factor out getting the stack decl index","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1e40b9fafad86c87adbe3d9c2a334ca544b8775f","submitter":{"id":93219,"url":"http://patchwork.ozlabs.org/api/1.2/people/93219/?format=json","name":"Andrew Pinski via Sourceware Forge","email":"forge-bot+pinskia@forge-stage.sourceware.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhubeob5uw.gcc.gcc-TEST.pinskia.21.1.2@forge-stage.sourceware.org/mbox/","series":[{"id":500980,"url":"http://patchwork.ozlabs.org/api/1.2/series/500980/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500980","date":"2026-04-22T10:31:24","name":"scoped_conflicts","version":1,"mbox":"http://patchwork.ozlabs.org/series/500980/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226270/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226270/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org","sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org","server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0x360yX7z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 20:55:46 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D7E854314EA5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 10:55:43 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id C061E4BBC08C\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:32:22 +0000 (GMT)","from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id 9B7D842B25\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:32:22 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D7E854314EA5","OpenDKIM Filter v2.11.0 sourceware.org C061E4BBC08C"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org C061E4BBC08C","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org C061E4BBC08C","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776853942; cv=none;\n b=i/83DhCJUMUtwRBQfvRTsty4Y1PpQwOwq5o0W5exE6SYcOuKYym9JII44l59b+rcCiWQ2UCv8MQ/ZVkzPjKh6Q/yNcJj1Lhne8t9nWhH7PTlXW+Sx7sOHNWNscJzTPl3bC9suZSqTK9zuhtDKakl4gryzh3uQHfU1XSpxcJ7KaM=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776853942; c=relaxed/simple;\n bh=knptEQ2hTkaiKR0tJgYbC7EgyuelRVNKDBmkTlagcJ0=;\n h=From:Date:Subject:To:Message-ID;\n b=cYSqfS7vd+850bNtDf2EmfgXtMfqehCfStIvw5lXMKNwW+2qbvJXz+TxXMWignVpgQaXifa9ydfkqxmQ3gaAVKiozU1AV1pKBzqCRSLUyacGE/ioTMD3bx7RRTFkI781R3arR+x08m8lf6CKnYxUlBvr6ebnxMCFXrtYwdFZn/Q=","ARC-Authentication-Results":"i=1; server2.sourceware.org","From":"Andrew Pinski via Sourceware Forge\n <forge-bot+pinskia@forge-stage.sourceware.org>","Date":"Wed, 22 Apr 2026 10:31:25 +0000","Subject":"[PATCH v1 2/4] cfgexpand: Factor out getting the stack decl index","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhubeob5uw.gcc.gcc-TEST.pinskia.21.1.2@forge-stage.sourceware.org>","X-Mailer":"batrachomyomachia","X-Pull-Request-Organization":"gcc","X-Pull-Request-Repository":"gcc-TEST","X-Pull-Request":"https://forge.sourceware.org/gcc/gcc-TEST/pulls/21","References":"\n <bmm.hhubeob5uw.gcc.gcc-TEST.pinskia.21.1.0@forge-stage.sourceware.org>","In-Reply-To":"\n <bmm.hhubeob5uw.gcc.gcc-TEST.pinskia.21.1.0@forge-stage.sourceware.org>","X-Patch-URL":"\n https://forge.sourceware.org/pinskia/gcc-TEST/commit/e24b18474c605c293e9e1c963684c2dca4e34887","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>,\n pinskia@gcc.gnu.org","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"From: Andrew Pinski <quic_apinski@quicinc.com>\n\nThis is the first patch in improving this code.\nSince there are a few places which get the index and they\ncheck the same thing, let's factor that out into one function.\n\nBootstrapped and tested on x86_64-linux-gnu.\n\ngcc/ChangeLog:\n\n\t* cfgexpand.cc (INVALID_STACK_INDEX): New defined.\n\t(decl_stack_index): New function.\n\t(visit_op): Use decl_stack_index.\n\t(visit_conflict): Likewise.\n\t(add_scope_conflicts_1): Likewise.\n\nSigned-off-by: Andrew Pinski <quic_apinski@quicinc.com>\n---\n gcc/cfgexpand.cc | 62 +++++++++++++++++++++++++++++-------------------\n 1 file changed, 37 insertions(+), 25 deletions(-)","diff":"diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc\nindex ed890f692e58..b88e8827667b 100644\n--- a/gcc/cfgexpand.cc\n+++ b/gcc/cfgexpand.cc\n@@ -338,6 +338,8 @@ static unsigned stack_vars_alloc;\n static unsigned stack_vars_num;\n static hash_map<tree, unsigned> *decl_to_stack_part;\n \n+#define INVALID_STACK_INDEX ((unsigned)-1)\n+\n /* Conflict bitmaps go on this obstack.  This allows us to destroy\n    all of them in one big sweep.  */\n static bitmap_obstack stack_var_bitmap_obstack;\n@@ -526,6 +528,27 @@ stack_var_conflict_p (unsigned x, unsigned y)\n   return bitmap_bit_p (a->conflicts, y);\n }\n \n+/* Returns the DECL's index into the stack_vars array.\n+   If the DECL does not exist return INVALID_STACK_INDEX.  */\n+static unsigned\n+decl_stack_index (tree decl)\n+{\n+  if (!decl)\n+    return INVALID_STACK_INDEX;\n+  if (!DECL_P (decl))\n+    return INVALID_STACK_INDEX;\n+  if (DECL_RTL_IF_SET (decl) != pc_rtx)\n+    return INVALID_STACK_INDEX;\n+  unsigned *v = decl_to_stack_part->get (decl);\n+  if (!v)\n+    return INVALID_STACK_INDEX;\n+\n+  unsigned indx = *v;\n+  gcc_checking_assert (indx != INVALID_STACK_INDEX);\n+  gcc_checking_assert (indx < stack_vars_num);\n+  return indx;\n+}\n+\n /* Callback for walk_stmt_ops.  If OP is a decl touched by add_stack_var\n    enter its partition number into bitmap DATA.  */\n \n@@ -534,14 +557,9 @@ visit_op (gimple *, tree op, tree, void *data)\n {\n   bitmap active = (bitmap)data;\n   op = get_base_address (op);\n-  if (op\n-      && DECL_P (op)\n-      && DECL_RTL_IF_SET (op) == pc_rtx)\n-    {\n-      unsigned *v = decl_to_stack_part->get (op);\n-      if (v)\n-\tbitmap_set_bit (active, *v);\n-    }\n+  unsigned idx = decl_stack_index (op);\n+  if (idx != INVALID_STACK_INDEX)\n+    bitmap_set_bit (active, idx);\n   return false;\n }\n \n@@ -554,20 +572,15 @@ visit_conflict (gimple *, tree op, tree, void *data)\n {\n   bitmap active = (bitmap)data;\n   op = get_base_address (op);\n-  if (op\n-      && DECL_P (op)\n-      && DECL_RTL_IF_SET (op) == pc_rtx)\n+  unsigned num = decl_stack_index (op);\n+  if (num != INVALID_STACK_INDEX\n+      && bitmap_set_bit (active, num))\n     {\n-      unsigned *v = decl_to_stack_part->get (op);\n-      if (v && bitmap_set_bit (active, *v))\n-\t{\n-\t  unsigned num = *v;\n-\t  bitmap_iterator bi;\n-\t  unsigned i;\n-\t  gcc_assert (num < stack_vars_num);\n-\t  EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi)\n-\t    add_stack_var_conflict (num, i);\n-\t}\n+      bitmap_iterator bi;\n+      unsigned i;\n+      gcc_assert (num < stack_vars_num);\n+      EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi)\n+\tadd_stack_var_conflict (num, i);\n     }\n   return false;\n }\n@@ -639,15 +652,14 @@ add_scope_conflicts_1 (basic_block bb, bitmap work, bool for_conflict)\n       if (gimple_clobber_p (stmt))\n \t{\n \t  tree lhs = gimple_assign_lhs (stmt);\n-\t  unsigned *v;\n \t  /* Handle only plain var clobbers.\n \t     Nested functions lowering and C++ front-end inserts clobbers\n \t     which are not just plain variables.  */\n \t  if (!VAR_P (lhs))\n \t    continue;\n-\t  if (DECL_RTL_IF_SET (lhs) == pc_rtx\n-\t      && (v = decl_to_stack_part->get (lhs)))\n-\t    bitmap_clear_bit (work, *v);\n+\t  unsigned indx = decl_stack_index (lhs);\n+\t  if (indx != INVALID_STACK_INDEX)\n+\t    bitmap_clear_bit (work, indx);\n \t}\n       else if (!is_gimple_debug (stmt))\n \t{\n","prefixes":["v1","2/4"]}