public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/55653] New: Unnecessary initialization of vector register
@ 2012-12-11 19:34 josh.m.conner at gmail dot com
  2012-12-11 20:06 ` [Bug middle-end/55653] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: josh.m.conner at gmail dot com @ 2012-12-11 19:34 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55653

             Bug #: 55653
           Summary: Unnecessary initialization of vector register
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: josh.m.conner@gmail.com


When initializing all lanes of a vector register, I notice that the register is
first initialized to zero and then all lanes of the vector are independently
initialized, resulting in extra code.

Specifically, I'm looking at the aarch64 target, with the following source:

void
fmla_loop (double * restrict result, double * restrict mul1,
       double mul2, int size)
{
  int i;

  for (i = 0; i < size; i++)
    result[i] = result[i] + mul1[i] * mul2;
}

Compiled with:

aarch64-linux-gnu-gcc -std=c99 -O3 -ftree-vectorize -S -o test.s test.c

The resultant code to initialize a vector register with two instances of mul2
is:

  adr     x3, .LC0
  ld1     {v3.2d}, [x3]
  ins     v3.d[0], v0.d[0]
  ins     v3.d[1], v0.d[0]
...
.LC0:
  .word   0
  .word   0
  .word   0
  .word   0

Where the first two instructions (that initialize the vector register) are
unnecessary, as is the space for .LC0.

Note that this initialization is being performed here in store_constructor:

        /* Inform later passes that the old value is dead.  */
        if (!cleared && !vector && REG_P (target))
          emit_move_insn (target, CONST0_RTX (GET_MODE (target)));

right after another check to see if the vector needs to be cleared out (and
determine that it doesn't).

Instead of the emit_move_insn, that code used to be:

       emit_insn (gen_rtx_CLOBBER (VOIDmode, target));

But was changed in r101169, with the comment:

  "The expr.c change elides an extra move that's creeped in since we
changed clobbered values to get new registers in reload."

(see full checkin text here:
http://gcc.gnu.org/ml/gcc-patches/2005-06/msg01584.html)

It's not clear to me whether this can be changed back, or if later passes
should be recognizing this initialization as redundant, or whether we need a
new expand pattern to match vector fill (vector duplicate).  At any rate, the
code is certainly not ideal as it stands.

Thanks!


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

* [Bug middle-end/55653] Unnecessary initialization of vector register
  2012-12-11 19:34 [Bug middle-end/55653] New: Unnecessary initialization of vector register josh.m.conner at gmail dot com
@ 2012-12-11 20:06 ` pinskia at gcc dot gnu.org
  2013-10-07  9:18 ` rearnsha at gcc dot gnu.org
  2013-10-07  9:31 ` rearnsha at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-12-11 20:06 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55653

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Target|                            |aarch64-*-*
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-12-11 20:06:00 UTC ---
I think there are two different issues here.  The first issue is a target issue
as {0.0, 0.0} should be done as just an xor which really resolves this issue as
it is able to optimize that out (though it is a good thing to do even without
the other part).

The other issue shouldn't !vector be false here as we have a vector?


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

* [Bug middle-end/55653] Unnecessary initialization of vector register
  2012-12-11 19:34 [Bug middle-end/55653] New: Unnecessary initialization of vector register josh.m.conner at gmail dot com
  2012-12-11 20:06 ` [Bug middle-end/55653] " pinskia at gcc dot gnu.org
@ 2013-10-07  9:18 ` rearnsha at gcc dot gnu.org
  2013-10-07  9:31 ` rearnsha at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2013-10-07  9:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55653

Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
Fixed with:

2013-01-08  Tejas Belagod  <tejas.belagod@arm.com>

    * config/aarch64/aarch64-simd.md (vec_init<mode>): New.
    * config/aarch64/aarch64-protos.h (aarch64_expand_vector_init):
    Declare.
    * config/aarch64/aarch64.c (aarch64_simd_dup_constant,
    aarch64_simd_make_constant, aarch64_expand_vector_init): New.


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

* [Bug middle-end/55653] Unnecessary initialization of vector register
  2012-12-11 19:34 [Bug middle-end/55653] New: Unnecessary initialization of vector register josh.m.conner at gmail dot com
  2012-12-11 20:06 ` [Bug middle-end/55653] " pinskia at gcc dot gnu.org
  2013-10-07  9:18 ` rearnsha at gcc dot gnu.org
@ 2013-10-07  9:31 ` rearnsha at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2013-10-07  9:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55653

--- Comment #3 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
On the secondary issue of initializing FP vectors to zero, we now generate for

typedef double f __attribute__((vector_size(16)));

f g()
{
  f a = {0.0, 0.0};
  return a;
}

g:
        movi    v0.2d, 0
        ret


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

end of thread, other threads:[~2013-10-07  9:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-11 19:34 [Bug middle-end/55653] New: Unnecessary initialization of vector register josh.m.conner at gmail dot com
2012-12-11 20:06 ` [Bug middle-end/55653] " pinskia at gcc dot gnu.org
2013-10-07  9:18 ` rearnsha at gcc dot gnu.org
2013-10-07  9:31 ` rearnsha 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).