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

Kewen Lin <linkw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |linkw at gcc dot gnu.org

--- Comment #8 from Kewen Lin <linkw at gcc dot gnu.org> ---
Haochen's patch r12-1202 helps to make the variable expansion work for this
case.

With GCC11, we get the RTL like:

  11: NOTE_INSN_BASIC_BLOCK 3
   12: r118:DI=r118:DI+0x4
   13: r128:SI=[r118:DI]
   14: r127:SI=r128:SI+r123:DI#0        // A
      REG_DEAD r128:SI
      REG_DEAD r123:DI
   15: r123:DI=sign_extend(r127:SI)     // B
      REG_DEAD r127:SI
   16: r129:SI=r119:DI#0-0x1
      REG_DEAD r119:DI
   17: r119:DI=zero_extend(r129:SI)
      REG_DEAD r129:SI
   19: r130:CC=cmp(r119:DI,0)
   20: pc={(r130:CC!=0)?L35:pc}

While with trunk, we get the RTL like:

   10: NOTE_INSN_BASIC_BLOCK 3
   11: r118:DI=r118:DI+0x4
   12: r127:SI=[r118:DI]
   13: r120:SI=r120:SI+r127:SI           // C
      REG_DEAD r127:SI
   14: r119:SI=r119:SI-0x1
   16: r128:CC=cmp(r119:SI,0)
   17: pc={(r128:CC!=0)?L33:pc}

We have A+B for the accumulation with GCC11 while just C with trunk. The C
pattern matches the check in function analyze_insn_to_expand_var, which is able
to record var_to_expand further.

The related code in analyze_insn_to_expand_var is:

  /* Find the accumulator use within the operation.  */
  if (code == FMA)
    {
      /* We only support accumulation via FMA in the ADD position.  */
      if (!rtx_equal_p  (dest, XEXP (src, 2)))
        return NULL;
      accum_pos = 2;
    }
  else if (rtx_equal_p (dest, XEXP (src, 0)))
    accum_pos = 0;
  else if (rtx_equal_p (dest, XEXP (src, 1)))
    {
      /* The method of expansion that we are using; which includes the
         initialization of the expansions with zero and the summation of
         the expansions at the end of the computation will yield wrong
         results for (x = something - x) thus avoid using it in that case.  */
      if (code == MINUS)
        return NULL;
      accum_pos = 1;
    }
  else
    return NULL;

The key is if dest can match XEXP (src, 0) or XEXP (src, 1).

Reply via email to