{"id":2226297,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2226297/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhubwh7m90.gcc.gcc-TEST.pinskia.33.1.10@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.hhubwh7m90.gcc.gcc-TEST.pinskia.33.1.10@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T10:49:19","name":"[v1,10/15] combine: Add REG_DEAD notes to the last instruction after a split [PR118914]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"195dba58fca22f7eb52713b7c3e0ba1f7f94a1b4","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.hhubwh7m90.gcc.gcc-TEST.pinskia.33.1.10@forge-stage.sourceware.org/mbox/","series":[{"id":500990,"url":"http://patchwork.ozlabs.org/api/1.2/series/500990/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500990","date":"2026-04-22T10:49:12","name":"copy-prop-arg","version":1,"mbox":"http://patchwork.ozlabs.org/series/500990/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226297/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226297/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 4g0xZf2xJgz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 21:19:38 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 947E34339F4B\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:19:36 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 5DF4241627CA\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:50:34 +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 D16BA42BDF\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:50:31 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 947E34339F4B","OpenDKIM Filter v2.11.0 sourceware.org 5DF4241627CA"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 5DF4241627CA","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 5DF4241627CA","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776855034; cv=none;\n b=T6R9mbZ1ErcHjmYeFgvxQKWVUPvPZHi2/aXF6qu76pwHbRISgQ5TpmEC7ZRnBE/a1/3QMv7s9uRo9/a5xproL8BMmV6Kv5PyGSI/pVPwb8jTvzs+Q2vvfDkhv8imV2076R2R/3JEFx9ekVhnqBnOutnuzlNC5B0xgdJDm374b0Y=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776855034; c=relaxed/simple;\n bh=kX2havAjvBfKsBvrHL935TaJj14yiJbn8dJplPYbs3Y=;\n h=From:Date:Subject:To:Message-ID;\n b=G0JfSLRupPMTgkvM8rrsIM0vf4n5JNi76BLtxIhMAvURyIPlN2I/oG8nmeI1ISlZzoqfztxlPWHiKsBYLnXxedu/bSYde0SbIZxezlTskTePrE9GLbIm6c791kamFine/NRgZ+OZ29nM7gFGXb09s6x0pjTEBTDMU0x106yyfX8=","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:49:19 +0000","Subject":"[PATCH v1 10/15] combine: Add REG_DEAD notes to the last instruction\n after a split [PR118914]","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhubwh7m90.gcc.gcc-TEST.pinskia.33.1.10@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/33","References":"\n <bmm.hhubwh7m90.gcc.gcc-TEST.pinskia.33.1.0@forge-stage.sourceware.org>","In-Reply-To":"\n <bmm.hhubwh7m90.gcc.gcc-TEST.pinskia.33.1.0@forge-stage.sourceware.org>","X-Patch-URL":"\n https://forge.sourceware.org/pinskia/gcc-TEST/commit/b51fb4933915f5a709aadb49915a72febc1d9699","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\nSo gcc.target/aarch64/rev16_2.c started to fail after r15-268-g9dbff9c05520a7,\nthe problem is combine now rejects the instruction combine. This happens because\nafter a different combine which uses a define_split and that define_split creates\na new pseudo register. That new pseudo register is dead after the last instruction\nin the stream BUT combine never creates a REG_DEAD for it. So combine thinks it is\nstill needed after and now with the i2 not changing, combine rejects the combine.\n\nNow combine should be creating a REG_DEAD for the new pseudo registers for the last\ninstruction of the split. This fixes rev16_2.c and also improves the situtation in\nother cases by removing other dead instructions.\n\nBootstrapped and tested on aarch64-linux-gnu and x86_64-linux-gnu.\n\ngcc/ChangeLog:\n\n\tPR rtl-optimization/118914\n\t* combine.cc (recog_for_combine): Add old_nregs and new_nregs\n\targument (defaulting to 0). Update call to recog_for_combine_1.\n\t(combine_split_insns): Add old_nregs and new_nregs arguments,\n\tstore the old and new max registers to them.\n\t(try_combine): Update calls to combine_split_insns and\n\tpass old_nregs and new_nregs for the i3 call to recog_for_combine.\n\t(find_split_point): Update call to combine_split_insns; ignoring\n\tthe values there.\n\t(recog_for_combine_1): Add old_nregs and new_nregs arguments,\n\tif the insn was recognized (and not to no-op move), add the\n\tREG_DEAD notes to pnotes argument.\n\nSigned-off-by: Andrew Pinski <quic_apinski@quicinc.com>\n---\n gcc/combine.cc | 46 +++++++++++++++++++++++++++++++---------------\n 1 file changed, 31 insertions(+), 15 deletions(-)","diff":"diff --git a/gcc/combine.cc b/gcc/combine.cc\nindex 3beeb514b817..a687c7c20158 100644\n--- a/gcc/combine.cc\n+++ b/gcc/combine.cc\n@@ -454,7 +454,7 @@ static bool merge_outer_ops (enum rtx_code *, HOST_WIDE_INT *, enum rtx_code,\n static rtx simplify_shift_const_1 (enum rtx_code, machine_mode, rtx, int);\n static rtx simplify_shift_const (rtx, enum rtx_code, machine_mode, rtx,\n \t\t\t\t int);\n-static int recog_for_combine (rtx *, rtx_insn *, rtx *);\n+static int recog_for_combine (rtx *, rtx_insn *, rtx *, unsigned = 0, unsigned = 0);\n static rtx gen_lowpart_for_combine (machine_mode, rtx);\n static enum rtx_code simplify_compare_const (enum rtx_code, machine_mode,\n \t\t\t\t\t     rtx *, rtx *);\n@@ -515,18 +515,22 @@ target_canonicalize_comparison (enum rtx_code *code, rtx *op0, rtx *op1,\n \n /* Try to split PATTERN found in INSN.  This returns NULL_RTX if\n    PATTERN cannot be split.  Otherwise, it returns an insn sequence.\n+   Updates OLD_NREGS with the max number of regs before the split\n+   and NEW_NREGS after the split.\n    This is a wrapper around split_insns which ensures that the\n    reg_stat vector is made larger if the splitter creates a new\n    register.  */\n \n static rtx_insn *\n-combine_split_insns (rtx pattern, rtx_insn *insn)\n+combine_split_insns (rtx pattern, rtx_insn *insn,\n+\t\t     unsigned int *old_nregs,\n+\t\t     unsigned int *new_regs)\n {\n   rtx_insn *ret;\n   unsigned int nregs;\n-\n+  *old_nregs = max_reg_num ();\n   ret = split_insns (pattern, insn);\n-  nregs = max_reg_num ();\n+  *new_regs = nregs = max_reg_num ();\n   if (nregs > reg_stat.length ())\n     reg_stat.safe_grow_cleared (nregs, true);\n   return ret;\n@@ -3566,12 +3570,13 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,\n     {\n       rtx parallel, *split;\n       rtx_insn *m_split_insn;\n+      unsigned int old_nregs, new_nregs;\n \n       /* See if the MD file can split NEWPAT.  If it can't, see if letting it\n \t use I2DEST as a scratch register will help.  In the latter case,\n \t convert I2DEST to the mode of the source of NEWPAT if we can.  */\n \n-      m_split_insn = combine_split_insns (newpat, i3);\n+      m_split_insn = combine_split_insns (newpat, i3, &old_nregs, &new_nregs);\n \n       /* We can only use I2DEST as a scratch reg if it doesn't overlap any\n \t inputs of NEWPAT.  */\n@@ -3599,7 +3604,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,\n \t\t\t\t       gen_rtvec (2, newpat,\n \t\t\t\t\t\t  gen_rtx_CLOBBER (VOIDmode,\n \t\t\t\t\t\t\t\t   i2dest)));\n-\t  m_split_insn = combine_split_insns (parallel, i3);\n+\t  m_split_insn = combine_split_insns (parallel, i3, &old_nregs, &new_nregs);\n \n \t  /* If that didn't work, try changing the mode of I2DEST if\n \t     we can.  */\n@@ -3624,7 +3629,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,\n \t\t\t   gen_rtvec (2, newpat,\n \t\t\t\t      gen_rtx_CLOBBER (VOIDmode,\n \t\t\t\t\t\t       ni2dest))));\n-\t      m_split_insn = combine_split_insns (parallel, i3);\n+\t      m_split_insn = combine_split_insns (parallel, i3, &old_nregs, &new_nregs);\n \n \t      if (m_split_insn == 0\n \t\t  && REGNO (i2dest) >= FIRST_PSEUDO_REGISTER)\n@@ -3647,13 +3652,14 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,\n       if (m_split_insn == 0 && newpat_vec_with_clobbers)\n \t{\n \t  parallel = gen_rtx_PARALLEL (VOIDmode, newpat_vec_with_clobbers);\n-\t  m_split_insn = combine_split_insns (parallel, i3);\n+\t  m_split_insn = combine_split_insns (parallel, i3, &old_nregs, &new_nregs);\n \t}\n \n       if (m_split_insn && NEXT_INSN (m_split_insn) == NULL_RTX)\n \t{\n \t  rtx m_split_pat = PATTERN (m_split_insn);\n-\t  insn_code_number = recog_for_combine (&m_split_pat, i3, &new_i3_notes);\n+\t  insn_code_number = recog_for_combine (&m_split_pat, i3, &new_i3_notes,\n+\t\t\t\t\t\told_nregs, new_nregs);\n \t  if (insn_code_number >= 0)\n \t    newpat = m_split_pat;\n \t}\n@@ -3678,7 +3684,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,\n \t      && (next_nonnote_nondebug_insn (i2) == i3\n \t\t  || ! reg_used_between_p (SET_DEST (i2set), i2, i3)))\n \t    insn_code_number = recog_for_combine (&newi3pat, i3,\n-\t\t\t\t\t\t  &new_i3_notes);\n+\t\t\t\t\t\t  &new_i3_notes,\n+\t\t\t\t\t\t  old_nregs, new_nregs);\n \t  if (insn_code_number >= 0)\n \t    newpat = newi3pat;\n \n@@ -4915,8 +4922,9 @@ find_split_point (rtx *loc, rtx_insn *insn, bool set_src)\n \t\t\t\t\t    MEM_ADDR_SPACE (x)))\n \t{\n \t  rtx reg = regno_reg_rtx[FIRST_PSEUDO_REGISTER];\n+\t  unsigned int old_nregs, new_nregs;\n \t  rtx_insn *seq = combine_split_insns (gen_rtx_SET (reg, XEXP (x, 0)),\n-\t\t\t\t\t       subst_insn);\n+\t\t\t\t\t       subst_insn, &old_nregs, &new_nregs);\n \n \t  /* This should have produced two insns, each of which sets our\n \t     placeholder.  If the source of the second is a valid address,\n@@ -11418,7 +11426,8 @@ simplify_shift_const (rtx x, enum rtx_code code, machine_mode result_mode,\n    return value.  */\n \n static int\n-recog_for_combine_1 (rtx *pnewpat, rtx_insn *insn, rtx *pnotes)\n+recog_for_combine_1 (rtx *pnewpat, rtx_insn *insn, rtx *pnotes,\n+\t\t     unsigned old_nregs, unsigned new_nregs)\n {\n   rtx pat = *pnewpat;\n   rtx pat_without_clobbers;\n@@ -11534,6 +11543,9 @@ recog_for_combine_1 (rtx *pnewpat, rtx_insn *insn, rtx *pnotes)\n   if (insn_code_number >= 0\n       && insn_code_number != NOOP_MOVE_INSN_CODE)\n     {\n+      /* Create the reg dead notes if needed for the regs that were created via split.   */\n+      for (; old_nregs < new_nregs; old_nregs++)\n+\tnotes = alloc_reg_note (REG_DEAD, regno_reg_rtx[old_nregs], notes);\n       old_pat = PATTERN (insn);\n       old_notes = REG_NOTES (insn);\n       old_icode = INSN_CODE (insn);\n@@ -11705,15 +11717,18 @@ change_zero_ext (rtx pat)\n \n    PNOTES is a pointer to a location where any REG_UNUSED notes added for\n    the CLOBBERs are placed.\n+   If OLD_NREGS != NEW_NREGS, then PNOTES also includes REG_DEAD notes added.\n \n    The value is the final insn code from the pattern ultimately matched,\n    or -1.  */\n \n static int\n-recog_for_combine (rtx *pnewpat, rtx_insn *insn, rtx *pnotes)\n+recog_for_combine (rtx *pnewpat, rtx_insn *insn, rtx *pnotes,\n+\t\t   unsigned int old_nregs, unsigned int new_nregs)\n {\n   rtx pat = *pnewpat;\n-  int insn_code_number = recog_for_combine_1 (pnewpat, insn, pnotes);\n+  int insn_code_number = recog_for_combine_1 (pnewpat, insn, pnotes,\n+\t\t\t\t\t      old_nregs, new_nregs);\n   if (insn_code_number >= 0 || check_asm_operands (pat))\n     return insn_code_number;\n \n@@ -11755,7 +11770,8 @@ recog_for_combine (rtx *pnewpat, rtx_insn *insn, rtx *pnotes)\n \n   if (changed)\n     {\n-      insn_code_number = recog_for_combine_1 (pnewpat, insn, pnotes);\n+      insn_code_number = recog_for_combine_1 (pnewpat, insn, pnotes,\n+\t\t\t\t\t      old_nregs, new_nregs);\n \n       if (insn_code_number < 0)\n \tundo_to_marker (marker);\n","prefixes":["v1","10/15"]}