https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80127

            Bug ID: 80127
           Summary: regrename_do_replace does not update the df refs
           Product: gcc
           Version: 6.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefan at franke dot ms
  Target Milestone: ---

The method regrename_do_replace does neither update the df refs nor reset the
ever_live flag. Also the passes for stack variables are scheduled to early.

This leads to eliminated variables which are still pushed/popped to/from stack
but are never used.



Old code:

bool
regrename_do_replace (struct du_head *head, int regno)
{
...
  mode = GET_MODE(*head->first->loc);
  head->renamed = 1;
  head->regno = regno;
  head->nregs = hard_regno_nregs[regno][mode];

  return true;
}

My code:

bool
regrename_do_replace (struct du_head *head, int regno)
{
...
  mode = GET_MODE(*head->first->loc);
  head->renamed = 1;
  head->regno = regno;
  head->nregs = hard_regno_nregs[regno][mode];

  /* SBF: also update the current df info, move from base_regno -> regno. */
  if (base_regno < FIRST_PSEUDO_REGISTER && regno < FIRST_PSEUDO_REGISTER)
    for (chain = head->first; chain; chain = chain->next_use)
      {
        if (DEBUG_INSN_P (chain->insn))
          continue;
        /* undo regno patch - will be patched again */
        if (REGNO (*chain->loc) == regno)
          SET_REGNO(*chain->loc, base_regno);
        df_ref_change_reg_with_loc (*chain->loc, regno);

        SET_REGNO(*chain->loc, regno);
      }

  /* SBF: Mark the old regno as no longer used. */
  if (!df->hard_regs_live_count[base_regno])
    df_set_regs_ever_live (base_regno, false);

  return true;
}

I also moved the stack creation passed after regrename:

passes.def:

...
          NEXT_PASS (pass_regrename);
          NEXT_PASS (pass_cprop_hardreg);
          NEXT_PASS (pass_thread_prologue_and_epilogue);
          NEXT_PASS (pass_rtl_dse2);
          NEXT_PASS (pass_stack_adjustments);
...


=> No more push/pop for unused variables due to regrename.

Reply via email to