public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/95125] New: Unoptimal code for vectorized conversions
@ 2020-05-14 10:04 ubizjak at gmail dot com
  2020-05-14 11:55 ` [Bug target/95125] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: ubizjak at gmail dot com @ 2020-05-14 10:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95125
           Summary: Unoptimal code for vectorized conversions
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Following testcase

--cut here--
float f[4];
double d[4];
int i[4];

void
float_truncate (void)
{
  for (int n = 0; n < 4; n++)
    f[n] = d[n];
}

void
float_extend (void)
{
  for (int n = 0; n < 4; n++)
    d[n] = f[n];
}

void
float_float (void)
{
  for (int n = 0; n < 4; n++)
    f[n] = i[n];
}

void
fix_float (void)
{
  for (int n = 0; n < 4; n++)
    i[n] = f[n];
}

void
float_double (void)
{
  for (int n = 0; n < 4; n++)
    d[n] = i[n];
}

void
fix_double (void)
{
  for (int n = 0; n < 4; n++)
    i[n] = d[n];
}
--cut here--

when compiled with "-O3 -mavx" should result in a single conversion
instruction.

float_truncate:
        vxorps  %xmm0, %xmm0, %xmm0
        vcvtsd2ss       d+8(%rip), %xmm0, %xmm2
        vmovaps %xmm2, %xmm3
        vcvtsd2ss       d(%rip), %xmm0, %xmm1
        vcvtsd2ss       d+16(%rip), %xmm0, %xmm2
        vcvtsd2ss       d+24(%rip), %xmm0, %xmm0
        vunpcklps       %xmm0, %xmm2, %xmm2
        vunpcklps       %xmm3, %xmm1, %xmm0
        vmovlhps        %xmm2, %xmm0, %xmm0
        vmovaps %xmm0, f(%rip)
        ret

float_extend:
        vcvtps2pd       f(%rip), %xmm0
        vmovapd %xmm0, d(%rip)
        vxorps  %xmm0, %xmm0, %xmm0
        vmovlps f+8(%rip), %xmm0, %xmm0
        vcvtps2pd       %xmm0, %xmm0
        vmovapd %xmm0, d+16(%rip)
        ret

float_float:
        vcvtdq2ps       i(%rip), %xmm0
        vmovaps %xmm0, f(%rip)
        ret

fix_float:
        vcvttps2dq      f(%rip), %xmm0
        vmovdqa %xmm0, i(%rip)
        ret

float_double:
        vcvtdq2pd       i(%rip), %xmm0
        vmovapd %xmm0, d(%rip)
        vpshufd $238, i(%rip), %xmm0
        vcvtdq2pd       %xmm0, %xmm0
        vmovapd %xmm0, d+16(%rip)
        ret

fix_double:
        pushq   %rbp
        vmovapd d(%rip), %xmm1
        vinsertf128     $0x1, d+16(%rip), %ymm1, %ymm0
        movq    %rsp, %rbp
        vcvttpd2dqy     %ymm0, %xmm0
        vmovdqa %xmm0, i(%rip)
        vzeroupper
        popq    %rbp
        ret

Clang manages to emit optimal code.

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

end of thread, other threads:[~2021-08-03  3:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 10:04 [Bug target/95125] New: Unoptimal code for vectorized conversions ubizjak at gmail dot com
2020-05-14 11:55 ` [Bug target/95125] " rguenth at gcc dot gnu.org
2020-05-14 12:40 ` ubizjak at gmail dot com
2020-05-14 12:43 ` ubizjak at gmail dot com
2020-05-21  7:23 ` crazylht at gmail dot com
2020-05-22  7:46 ` crazylht at gmail dot com
2020-05-22  8:00 ` ubizjak at gmail dot com
2020-05-22  8:56 ` rguenth at gcc dot gnu.org
2020-05-22  9:18 ` rsandifo at gcc dot gnu.org
2020-05-25  1:58 ` cvs-commit at gcc dot gnu.org
2021-08-03  3:28 ` pinskia at gcc dot gnu.org
2021-08-03  3:35 ` crazylht at gmail dot com

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