public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "linkw at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/102062] powerpc suboptimal unrolling simple array sum
Date: Wed, 25 Aug 2021 15:31:33 +0000	[thread overview]
Message-ID: <bug-102062-4-Gu7IbZqnCL@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102062-4@http.gcc.gnu.org/bugzilla/>

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).

  parent reply	other threads:[~2021-08-25 15:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 11:27 [Bug c/102062] New: " npiggin at gmail dot com
2021-08-25 11:52 ` [Bug c/102062] " wschmidt at gcc dot gnu.org
2021-08-25 11:55 ` wschmidt at gcc dot gnu.org
2021-08-25 12:43 ` npiggin at gmail dot com
2021-08-25 12:50 ` wschmidt at gcc dot gnu.org
2021-08-25 13:01 ` npiggin at gmail dot com
2021-08-25 14:05 ` segher at gcc dot gnu.org
2021-08-25 14:10 ` segher at gcc dot gnu.org
2021-08-25 15:31 ` linkw at gcc dot gnu.org [this message]
2021-08-25 17:07 ` segher at gcc dot gnu.org
2021-08-25 18:01 ` wschmidt at gcc dot gnu.org
2021-08-25 18:03 ` dje at gcc dot gnu.org
2021-08-25 22:43 ` segher at gcc dot gnu.org
2021-08-25 23:29 ` [Bug rtl-optimization/102062] " dje at gcc dot gnu.org
2021-08-26  0:17 ` npiggin at gmail dot com
2021-08-30 17:34 ` segher at gcc dot gnu.org
2021-09-22 13:53 ` npiggin at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102062-4-Gu7IbZqnCL@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).