public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/48701] New: [missed optimization] GCC fails to use aliasing of ymm and xmm registers
@ 2011-04-20 13:26 kretz at kde dot org
  2011-04-20 13:27 ` [Bug target/48701] " kretz at kde dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: kretz at kde dot org @ 2011-04-20 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [missed optimization] GCC fails to use aliasing of ymm
                    and xmm registers
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kretz@kde.org


The two functions in the attached test case demonstrate the problem. The
intermediate stores/loads on the stack really should be optimized away.

testStore output now:
vmovdqa %xmm1,-0x30(%rsp)   
vmovdqa %xmm0,-0x20(%rsp)   
vmovdqa -0x30(%rsp),%ymm0   
vmovdqa %ymm0,(<blackhole>)

should be either:
vinsertf128 $1,%xmm0,%ymm1,%ymm0
vmovdqa %ymm0,(<blackhole>)

or:
vmovdqa %xmm1,(<blackhole>)
vmovdqa %xmm0,0x10(<blackhole>)

depending on the target microarchitecture and accompanying code.

likewise the testLoad output now is:
vmovdqa (<blackhole>),%ymm0
vmovdqa %ymm0,-0x30(%rsp)
vmovdqa -0x20(%rsp),%xmm1
vmovdqa -0x30(%rsp),%xmm0

and should be either:
vmovdqa (<blackhole>),%ymm0
vextractf128 $1,%ymm0,%xmm1

or:
vmovdqa (<blackhole>),%xmm0
vmovdqa 0x10(<blackhole>),%xmm1


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

* [Bug target/48701] [missed optimization] GCC fails to use aliasing of ymm and xmm registers
  2011-04-20 13:26 [Bug target/48701] New: [missed optimization] GCC fails to use aliasing of ymm and xmm registers kretz at kde dot org
@ 2011-04-20 13:27 ` kretz at kde dot org
  2011-04-20 13:49 ` rguenth at gcc dot gnu.org
  2023-05-15  6:54 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: kretz at kde dot org @ 2011-04-20 13:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Matthias Kretz <kretz at kde dot org> 2011-04-20 13:26:56 UTC ---
Created attachment 24060
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24060
testcase


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

* [Bug target/48701] [missed optimization] GCC fails to use aliasing of ymm and xmm registers
  2011-04-20 13:26 [Bug target/48701] New: [missed optimization] GCC fails to use aliasing of ymm and xmm registers kretz at kde dot org
  2011-04-20 13:27 ` [Bug target/48701] " kretz at kde dot org
@ 2011-04-20 13:49 ` rguenth at gcc dot gnu.org
  2023-05-15  6:54 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-20 13:49 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2011.04.20 13:49:21
     Ever Confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-20 13:49:21 UTC ---
Confirmed.


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

* [Bug target/48701] [missed optimization] GCC fails to use aliasing of ymm and xmm registers
  2011-04-20 13:26 [Bug target/48701] New: [missed optimization] GCC fails to use aliasing of ymm and xmm registers kretz at kde dot org
  2011-04-20 13:27 ` [Bug target/48701] " kretz at kde dot org
  2011-04-20 13:49 ` rguenth at gcc dot gnu.org
@ 2023-05-15  6:54 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-15  6:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Better testcase without inline-asm (because sometimes inline-asm gets in the
way of other optimizations):
```
#include <x86intrin.h>

__m256i blackhole;

void testStore(__m128i xmm0, __m128i xmm1)
{
    __m256i ymm;
    __m128i *xmm = (__m128i *)&ymm;
    xmm[0] = xmm0;
    xmm[1] = xmm1;
    blackhole = ymm;
}
void f(__m128i, __m128i);

void testLoad()
{
    __m256i ymm = blackhole;
    __m128i *xmm = (__m128i *)&ymm;
    f(xmm[0], xmm[1]);
}
```
testStore still needs some help:
  ymm_6 = BIT_INSERT_EXPR <ymm_5(D), xmm0_2(D), 0>;
  ymm_7 = BIT_INSERT_EXPR <ymm_6, xmm1_3(D), 128>;
  blackhole = ymm_7;

Which gives:
```
...
        vpxor   %xmm2, %xmm2, %xmm2
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        andq    $-32, %rsp
        vmovdqa %ymm2, -32(%rsp)
        vmovdqa %xmm0, -32(%rsp)
        vmovdqa %xmm1, -16(%rsp)
        vmovdqa -32(%rsp), %ymm4
        vmovdqa %ymm4, blackhole(%rip)
...
```

while testLoad is fine/correct:
testLoad:
        vmovdqa blackhole+16(%rip), %xmm1
        vmovdqa blackhole(%rip), %xmm0
        jmp     f

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

end of thread, other threads:[~2023-05-15  6:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-20 13:26 [Bug target/48701] New: [missed optimization] GCC fails to use aliasing of ymm and xmm registers kretz at kde dot org
2011-04-20 13:27 ` [Bug target/48701] " kretz at kde dot org
2011-04-20 13:49 ` rguenth at gcc dot gnu.org
2023-05-15  6:54 ` pinskia 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).