public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111697] New: Sub optimal code gen for initialising vector using loop
@ 2023-10-04 19:25 prathamesh3492 at gcc dot gnu.org
  2023-10-04 19:31 ` [Bug tree-optimization/111697] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: prathamesh3492 at gcc dot gnu.org @ 2023-10-04 19:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111697
           Summary: Sub optimal code gen for initialising vector using
                    loop
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: prathamesh3492 at gcc dot gnu.org
  Target Milestone: ---

Hi,
For the following test-case:

typedef int v4si __attribute__((vector_size (sizeof (int) * 4)));
v4si f(int x)
{
  v4si v;
  for (int i = 0; i < 4; i++)
    v[i] = x;
  return v;
}

Compiling with -O2 results in following .optimized dump:

v4si f (int x)
{
  v4si v;

  <bb 2> [local count: 214748368]:
  v_16 = BIT_INSERT_EXPR <v_12(D), x_6(D), 0 (32 bits)>;
  v_20 = BIT_INSERT_EXPR <v_16, x_6(D), 32 (32 bits)>;
  v_24 = BIT_INSERT_EXPR <v_20, x_6(D), 64 (32 bits)>;
  v_2 = BIT_INSERT_EXPR <v_24, x_6(D), 96 (32 bits)>;
  return v_2;

}

and following code-gen on aarch64:
f:
        movi    v0.4s, 0
        fmov    s31, w0
        ins     v0.s[0], v31.s[0]
        ins     v0.s[1], v31.s[0]
        ins     v0.s[2], v31.s[0]
        ins     v0.s[3], v31.s[0]
        ret

which could instead be a single dup instruction:
f:
        dup     v0.4s, w0
        ret

Similarly, code-gen on x86_64:
f:
        movd    %edi, %xmm0
        movd    %edi, %xmm1
        pshufd  $225, %xmm0, %xmm0
        movss   %xmm1, %xmm0
        pshufd  $225, %xmm0, %xmm0
        pshufd  $198, %xmm0, %xmm0
        movss   %xmm1, %xmm0
        pshufd  $198, %xmm0, %xmm0
        pshufd  $39, %xmm0, %xmm0
        movss   %xmm1, %xmm0
        pshufd  $39, %xmm0, %xmm0
        ret

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-05  7:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04 19:25 [Bug tree-optimization/111697] New: Sub optimal code gen for initialising vector using loop prathamesh3492 at gcc dot gnu.org
2023-10-04 19:31 ` [Bug tree-optimization/111697] " pinskia at gcc dot gnu.org
2023-10-05  7:46 ` rguenth at gcc dot gnu.org
2023-10-05  7:48 ` rguenth at gcc dot gnu.org

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