public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/103797] Clang vectorized LightPixel while GCC does not
Date: Wed, 22 Dec 2021 13:44:10 +0000	[thread overview]
Message-ID: <bug-103797-4-US1NMQQg6o@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103797-4@http.gcc.gnu.org/bugzilla/>

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

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #7 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
OK, here is completely fake testcase that does similar operaitons:

#include <math.h>
struct test {float x; float y; float z;} test;
float f;
void
t()
{
  float x = test.x;
  float y = test.y;
  float z = test.z;

  x = x * f;
  y = y * f;
  z = z * f;
  x = sqrt (x);
  y = sqrt (y);
  z = sqrt (z);
  x = x / f;
  y = y / f;
  z = z / f;
  test.x=x;
  test.y=y;
  test.z=z;
}

We seem to fail to vectorize it with:

t.c:20:9: missed:   op not supported by target.                                 
t.c:17:5: missed:   not vectorized: relevant stmt not supported: x_15 = x_24 /
f.0_1;

clang seems to use divps happilly, so I am not sure why it is not supported.
Even more funny is that with -Ofast it is compiled into multiplication by
reciprocal:

t:
.LFB0:
        .cfi_startproc
        movss   f(%rip), %xmm4
        movss   .LC0(%rip), %xmm2
        movss   test(%rip), %xmm0
        movss   test+4(%rip), %xmm3
        divss   %xmm4, %xmm2
        movss   test+8(%rip), %xmm1
        mulss   %xmm4, %xmm0
        mulss   %xmm4, %xmm3
        mulss   %xmm4, %xmm1
        sqrtss  %xmm0, %xmm0
        sqrtss  %xmm3, %xmm3
        sqrtss  %xmm1, %xmm1
        mulss   %xmm2, %xmm0
        mulss   %xmm2, %xmm3
        mulss   %xmm2, %xmm1
        unpcklps        %xmm3, %xmm0
        movlps  %xmm0, test(%rip)
        movss   %xmm1, test+8(%rip)
        ret


and rewriting it that way by hand:

#include <math.h>
struct test {float x; float y; float z;} test;
float f;
void
t()
{
  float x = test.x;
  float y = test.y;
  float z = test.z;
  float m = 1/f;

  x = x * f;
  y = y * f;
  z = z * f;
  x = sqrt (x);
  y = sqrt (y);
  z = sqrt (z);
  x = x * m;
  y = y * m;
  z = z * m;
  test.x=x;
  test.y=y;
  test.z=z;
}

gets the expected result:
t:
.LFB0:
        .cfi_startproc
        movss   f(%rip), %xmm0
        movq    test(%rip), %xmm1
        movaps  %xmm0, %xmm2
        shufps  $0xe0, %xmm2, %xmm2
        mulps   %xmm1, %xmm2
        movss   .LC0(%rip), %xmm1
        divss   %xmm0, %xmm1
        mulss   test+8(%rip), %xmm0
        sqrtps  %xmm2, %xmm2
        sqrtss  %xmm0, %xmm0
        movaps  %xmm1, %xmm3
        shufps  $0xe0, %xmm3, %xmm3
        mulss   %xmm0, %xmm1
        mulps   %xmm3, %xmm2
        movss   %xmm1, test+8(%rip)
        movlps  %xmm2, test(%rip)
        ret
        .cfi_endproc

Having this however I do not see slp analyzing the divide in the original code
at all.

  parent reply	other threads:[~2021-12-22 13:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 23:29 [Bug tree-optimization/103797] New: " hubicka at gcc dot gnu.org
2021-12-22  1:16 ` [Bug tree-optimization/103797] " pinskia at gcc dot gnu.org
2021-12-22  8:46 ` marxin at gcc dot gnu.org
2021-12-22  9:14 ` hubicka at kam dot mff.cuni.cz
2021-12-22  9:21 ` marxin at gcc dot gnu.org
2021-12-22 11:08 ` hubicka at kam dot mff.cuni.cz
2021-12-22 11:08 ` hubicka at kam dot mff.cuni.cz
2021-12-22 11:30 ` marxin at gcc dot gnu.org
2021-12-22 13:44 ` hubicka at gcc dot gnu.org [this message]
2021-12-22 14:30 ` pinskia at gcc dot gnu.org
2021-12-22 14:59 ` hubicka at kam dot mff.cuni.cz
2021-12-22 19:34 ` jakub at gcc dot gnu.org
2021-12-22 20:29 ` hubicka at gcc dot gnu.org
2021-12-23  8:12 ` ubizjak at gmail dot com
2021-12-23  8:52 ` ubizjak at gmail dot com
2021-12-23  8:58 ` ubizjak at gmail dot com
2021-12-23  9:15 ` jakub at gcc dot gnu.org
2021-12-23  9:47 ` hubicka at kam dot mff.cuni.cz
2021-12-23 11:16 ` ubizjak at gmail dot com
2021-12-24 16:10 ` cvs-commit at gcc dot gnu.org
2022-01-03 13:37 ` hubicka at gcc dot gnu.org
2022-01-04 13:16 ` rguenth at gcc dot gnu.org
2022-01-07  6:39 ` pinskia at gcc dot gnu.org

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-103797-4-US1NMQQg6o@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).