{"id":2226763,"url":"http://patchwork.ozlabs.org/api/patches/2226763/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhup4p5wp2.gcc.gcc-TEST.pinskia.84.1.2@forge-stage.sourceware.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/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.hhup4p5wp2.gcc.gcc-TEST.pinskia.84.1.2@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T18:49:10","name":"[v1,02/10] fab: Manaully build gimple rather than depend on gimplifier for stdarg functions","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1a073ace1119258935e0603df3ae65bb51a60d10","submitter":{"id":93219,"url":"http://patchwork.ozlabs.org/api/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.hhup4p5wp2.gcc.gcc-TEST.pinskia.84.1.2@forge-stage.sourceware.org/mbox/","series":[{"id":501092,"url":"http://patchwork.ozlabs.org/api/series/501092/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501092","date":"2026-04-22T18:49:11","name":"remove_fab","version":1,"mbox":"http://patchwork.ozlabs.org/series/501092/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226763/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226763/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=38.145.34.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 [38.145.34.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 4g18PN0P1Rz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 05:27:20 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 08BCE43B49A8\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 19:27:18 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id B8C7340A2C58\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:50:41 +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 8D43D43591\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:50:41 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 08BCE43B49A8","OpenDKIM Filter v2.11.0 sourceware.org B8C7340A2C58"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org B8C7340A2C58","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org B8C7340A2C58","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776883841; cv=none;\n b=ESSKxN24WprGqICP0kFa9JDPUYkfS3Qr7D+lPcwKqYp5R1V/bEiV4EZxp2LdwxFSaisa050YnADEPKXB2Nu2T3wEve2+KdiiSOaGO5UVNoa+UBSI7Xf14D5f+aBKomm15Wvvn9SkRCqCl+BWEiS4FAniKC6HGUG5ZJUDXew8DQo=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776883841; c=relaxed/simple;\n bh=sJxsG5iqlyHXsp/qEOnDq7OMzHEkFvwHgUHFZx+MlDI=;\n h=From:Date:Subject:To:Message-ID;\n b=NfxAer2j1vZieBNhTAOFweMSmqpPSeBtt8DZjCNwKGs7SIaVDI7fSde9Amr0lP3i2tzu7mEKkjlncU7yjGH9cYbbXExBLOkjFD/3bPwA1PsGWjBd8YYwD9I563KVNr0NxEdswtkGMuzG4Y+wxL+T0srSYSD3yCZzAVGzIV/6cm4=","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 18:49:10 +0000","Subject":"[PATCH v1 02/10] fab: Manaully build gimple rather than depend on\n gimplifier for stdarg functions","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhup4p5wp2.gcc.gcc-TEST.pinskia.84.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/84","References":"\n <bmm.hhup4p5wp2.gcc.gcc-TEST.pinskia.84.1.0@forge-stage.sourceware.org>","In-Reply-To":"\n <bmm.hhup4p5wp2.gcc.gcc-TEST.pinskia.84.1.0@forge-stage.sourceware.org>","X-Patch-URL":"\n https://forge.sourceware.org/pinskia/gcc-TEST/commit/996b40116bd60a9afb2a1c5eb4399c6080b9e389","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 <andrew.pinski@oss.qualcomm.com>\n\nThis code dates before gimple tuples was around. So it uses both MODIFY_EXPR and\nINDIRECT_REF :).\nFor `__builtin_va_start(ptr, 0)` it exands into:\n```\n_t = __builtin_next_arg (0);\n*ptr = _t;\n```\nWe need to get a new VDEF for the next arg call so we don't need to do a\nssa update too.\n\nFor `__builtin_va_copy(ptr, b)`, it expands into:\n```\n*ptr = b;\n```\nWhich is still a store.\n\nFor `__builtin_va_end(ptr)`, we change it into a GIMPLE_NOP.\n\nSince we don't return a value, we need to also set TODO_update_address_taken\non the todo manually too.\n\nNote this code will be moved into gimple_fold later on. This is part of the\nreason for updating this code. The other side is this simplifies the code\ntoo.\n\ngcc/ChangeLog:\n\n\t* tree-ssa-ccp.cc (optimize_stdarg_builtin): Mannually create the\n\tgimple statements instead of depending on the gimplifier.\n\t(pass_fold_builtins::execute): Handle updated call to optimize_stdarg_builtin.\n\nSigned-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>\n---\n gcc/tree-ssa-ccp.cc | 87 ++++++++++++++++++++++++++++++++++-----------\n 1 file changed, 66 insertions(+), 21 deletions(-)","diff":"diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc\nindex 1fbc3de2bfe7..c9ffd2af85c2 100644\n--- a/gcc/tree-ssa-ccp.cc\n+++ b/gcc/tree-ssa-ccp.cc\n@@ -3175,14 +3175,16 @@ optimize_stack_restore (gimple_stmt_iterator i)\n /* If va_list type is a simple pointer and nothing special is needed,\n    optimize __builtin_va_start (&ap, 0) into ap = __builtin_next_arg (0),\n    __builtin_va_end (&ap) out as NOP and __builtin_va_copy into a simple\n-   pointer assignment.  */\n+   pointer assignment.  Returns true if a change happened.  */\n \n-static tree\n-optimize_stdarg_builtin (gimple *call)\n+static bool\n+optimize_stdarg_builtin (gimple_stmt_iterator *gsi, gimple *call)\n {\n   tree callee, lhs, rhs, cfun_va_list;\n   bool va_list_simple_ptr;\n   location_t loc = gimple_location (call);\n+  gimple *nstmt0, *nstmt;\n+  tree tlhs, oldvdef, newvdef;\n \n   callee = gimple_call_fndecl (call);\n \n@@ -3197,48 +3199,90 @@ optimize_stdarg_builtin (gimple *call)\n       if (!va_list_simple_ptr\n \t  || targetm.expand_builtin_va_start != NULL\n \t  || !builtin_decl_explicit_p (BUILT_IN_NEXT_ARG))\n-\treturn NULL_TREE;\n+\treturn false;\n \n       if (gimple_call_num_args (call) != 2)\n-\treturn NULL_TREE;\n+\treturn false;\n \n       lhs = gimple_call_arg (call, 0);\n       if (!POINTER_TYPE_P (TREE_TYPE (lhs))\n \t  || TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (lhs)))\n \t     != TYPE_MAIN_VARIANT (cfun_va_list))\n-\treturn NULL_TREE;\n+\treturn false;\n+      /* Create `tlhs = __builtin_next_arg(0);`. */\n+      tlhs = make_ssa_name (cfun_va_list);\n+      nstmt0 = gimple_build_call (builtin_decl_explicit (BUILT_IN_NEXT_ARG), 1, integer_zero_node);\n+      lhs = fold_build2 (MEM_REF, cfun_va_list, lhs, build_zero_cst (TREE_TYPE (lhs)));\n+      gimple_call_set_lhs (nstmt0, tlhs);\n+      gimple_set_location (nstmt0, loc);\n+      gimple_move_vops (nstmt0, call);\n+      gsi_replace (gsi, nstmt0, false);\n+      oldvdef = gimple_vdef (nstmt0);\n+      newvdef = make_ssa_name (gimple_vop (cfun), nstmt0);\n+      gimple_set_vdef (nstmt0, newvdef);\n+\n+      /* Create `*lhs = tlhs;`.  */\n+      nstmt = gimple_build_assign (lhs, tlhs);\n+      gimple_set_location (nstmt, loc);\n+      gimple_set_vuse (nstmt, newvdef);\n+      gimple_set_vdef (nstmt, oldvdef);\n+      SSA_NAME_DEF_STMT (oldvdef) = nstmt;\n+      gsi_insert_after (gsi, nstmt, GSI_NEW_STMT);\n \n-      lhs = build_fold_indirect_ref_loc (loc, lhs);\n-      rhs = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_NEXT_ARG),\n-                             1, integer_zero_node);\n-      rhs = fold_convert_loc (loc, TREE_TYPE (lhs), rhs);\n-      return build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, rhs);\n+      if (dump_file && (dump_flags & TDF_DETAILS))\n+\t{\n+\t  fprintf (dump_file, \"Simplified\\n  \");\n+\t  print_gimple_stmt (dump_file, call, 0, dump_flags);\n+\t  fprintf (dump_file, \"into\\n  \");\n+\t  print_gimple_stmt (dump_file, nstmt0, 0, dump_flags);\n+\t  fprintf (dump_file, \"  \");\n+\t  print_gimple_stmt (dump_file, nstmt, 0, dump_flags);\n+\t}\n+      return true;\n \n     case BUILT_IN_VA_COPY:\n       if (!va_list_simple_ptr)\n-\treturn NULL_TREE;\n+\treturn false;\n \n       if (gimple_call_num_args (call) != 2)\n-\treturn NULL_TREE;\n+\treturn false;\n \n       lhs = gimple_call_arg (call, 0);\n       if (!POINTER_TYPE_P (TREE_TYPE (lhs))\n \t  || TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (lhs)))\n \t     != TYPE_MAIN_VARIANT (cfun_va_list))\n-\treturn NULL_TREE;\n-\n-      lhs = build_fold_indirect_ref_loc (loc, lhs);\n+\treturn false;\n       rhs = gimple_call_arg (call, 1);\n       if (TYPE_MAIN_VARIANT (TREE_TYPE (rhs))\n \t  != TYPE_MAIN_VARIANT (cfun_va_list))\n-\treturn NULL_TREE;\n+\treturn false;\n \n-      rhs = fold_convert_loc (loc, TREE_TYPE (lhs), rhs);\n-      return build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, rhs);\n+      lhs = fold_build2 (MEM_REF, cfun_va_list, lhs, build_zero_cst (TREE_TYPE (lhs)));\n+      nstmt = gimple_build_assign (lhs, rhs);\n+      gimple_set_location (nstmt, loc);\n+      gimple_move_vops (nstmt, call);\n+      gsi_replace (gsi, nstmt, false);\n+\n+      if (dump_file && (dump_flags & TDF_DETAILS))\n+\t{\n+\t  fprintf (dump_file, \"Simplified\\n  \");\n+\t  print_gimple_stmt (dump_file, call, 0, dump_flags);\n+\t  fprintf (dump_file, \"into\\n  \");\n+\t  print_gimple_stmt (dump_file, nstmt, 0, dump_flags);\n+\t}\n+      return true;\n \n     case BUILT_IN_VA_END:\n       /* No effect, so the statement will be deleted.  */\n-      return integer_zero_node;\n+      if (dump_file && (dump_flags & TDF_DETAILS))\n+\t{\n+\t  fprintf (dump_file, \"Removed\\n  \");\n+\t  print_gimple_stmt (dump_file, call, 0, dump_flags);\n+\t}\n+      unlink_stmt_vdef (call);\n+      release_defs (call);\n+      gsi_replace (gsi, gimple_build_nop (), true);\n+      return true;\n \n     default:\n       gcc_unreachable ();\n@@ -4426,7 +4470,8 @@ pass_fold_builtins::execute (function *fun)\n \t\tcase BUILT_IN_VA_END:\n \t\tcase BUILT_IN_VA_COPY:\n \t\t  /* These shouldn't be folded before pass_stdarg.  */\n-\t\t  result = optimize_stdarg_builtin (stmt);\n+\t\t  if (optimize_stdarg_builtin (&i, stmt))\n+\t\t    todoflags |= TODO_update_address_taken;\n \t\t  break;\n \n \t\tdefault:;\n","prefixes":["v1","02/10"]}