]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/df-problems.c
df: Record all definitions in DF_LR_BB_INFO->def [PR98863]
authorRichard Sandiford <richard.sandiford@arm.com>
Fri, 12 Feb 2021 15:54:48 +0000 (15:54 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Fri, 12 Feb 2021 15:54:48 +0000 (15:54 +0000)
commitf60226fd72331398dd5fd239e9d1b4feccc91988
tree87e31f6a45c95a67487356d0425811c94bdb4d42
parentb7210405ed8eb5fd723b2c99960dcc5f0aec89b4
df: Record all definitions in DF_LR_BB_INFO->def [PR98863]

df_lr_bb_local_compute has:

      FOR_EACH_INSN_INFO_DEF (def, insn_info)
/* If the def is to only part of the reg, it does
   not kill the other defs that reach here.  */
if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))

However, as noted in the comment in the patch and below, almost all
partial definitions have an associated use.  This means that the
confluence function:

  IN = (OUT & ~DEF) | USE

is unaffected by whether partial definitions are in DEF or not.

Even though the choice doesn't matter for the LR problem itself,
it's IMO much more convenient for consumers if DEF contains all the
definitions in the block.  The only pre-RTL-SSA code that tries to
consume DEF directly is shrink-wrap.c, which already has to work
around the incompleteness of the information:

  /* DF_LR_BB_INFO (bb)->def does not comprise the DF_REF_PARTIAL and
     DF_REF_CONDITIONAL defs.  So if DF_LIVE doesn't exist, i.e.
     at -O1, just give up searching NEXT_BLOCK.  */

I hit the same problem when trying to fix the RTL-SSA part of PR98863.

This patch treats partial definitions as both a def and a use,
just like the df_ref records almost always do.

To show that partial definitions almost always have uses:

  DF_REF_CONDITIONAL:

    Added by:

      case COND_EXEC:
df_defs_record (collection_rec, COND_EXEC_CODE (x),
bb, insn_info, DF_REF_CONDITIONAL);
break;

    Later, df_get_conditional_uses creates uses for all DF_REF_CONDITIONAL
    definitions.

  DF_REF_PARTIAL:

    In total, there are 4 locations at which we add partial definitions.

    Case 1:

      if (GET_CODE (dst) == STRICT_LOW_PART)
{
  flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;

  loc = &XEXP (dst, 0);
  dst = *loc;
}

    Corresponding use:

      case STRICT_LOW_PART:
{
  rtx *temp = &XEXP (dst, 0);
  /* A strict_low_part uses the whole REG and not just the
   SUBREG.  */
  dst = XEXP (dst, 0);
  df_uses_record (collection_rec,
  (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
  DF_REF_REG_USE, bb, insn_info,
  DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART);
}
break;

    Case 2:

      if (GET_CODE (dst) == ZERO_EXTRACT)
{
  flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;

  loc = &XEXP (dst, 0);
  dst = *loc;
}

    Corresponding use:

      case ZERO_EXTRACT:
{
  df_uses_record (collection_rec, &XEXP (dst, 1),
  DF_REF_REG_USE, bb, insn_info, flags);
  df_uses_record (collection_rec, &XEXP (dst, 2),
  DF_REF_REG_USE, bb, insn_info, flags);
  if (GET_CODE (XEXP (dst,0)) == MEM)
    df_uses_record (collection_rec, &XEXP (dst, 0),
    DF_REF_REG_USE, bb, insn_info,
    flags);
  else
    df_uses_record (collection_rec, &XEXP (dst, 0),
    DF_REF_REG_USE, bb, insn_info,
    DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT);
----------------------------^^^^^^^^^^^^^^^^^
}
break;

    Case 3:

      else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
{
  if (read_modify_subreg_p (dst))
    flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;

  flags |= DF_REF_SUBREG;

  df_ref_record (DF_REF_REGULAR, collection_rec,
 dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
}

    Corresponding use:

      case SUBREG:
if (read_modify_subreg_p (dst))
  {
    df_uses_record (collection_rec, &SUBREG_REG (dst),
    DF_REF_REG_USE, bb, insn_info,
    flags | DF_REF_READ_WRITE | DF_REF_SUBREG);
    break;
  }

    Case 4:

      /*  If this is a multiword hardreg, we create some extra
  datastructures that will enable us to easily build REG_DEAD
  and REG_UNUSED notes.  */
      if (collection_rec
  && (endregno != regno + 1) && insn_info)
{
  /* Sets to a subreg of a multiword register are partial.
     Sets to a non-subreg of a multiword register are not.  */
  if (GET_CODE (reg) == SUBREG)
    ref_flags |= DF_REF_PARTIAL;
  ref_flags |= DF_REF_MW_HARDREG;

    Corresponding use:

      None.  However, this case should be rare to non-existent on most
      targets, and the current handling seems suspect.  See the comment
      in the patch for more details.

gcc/
* df-problems.c (df_lr_bb_local_compute): Treat partial definitions
as read-modify operations.

gcc/testsuite/
* gcc.dg/rtl/aarch64/multi-subreg-1.c: New test.
gcc/df-problems.c
gcc/testsuite/gcc.dg/rtl/aarch64/multi-subreg-1.c [new file with mode: 0644]