public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float
@ 2023-02-15 14:16 vincenzo.innocente at cern dot ch
  2023-02-15 20:28 ` [Bug tree-optimization/108804] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2023-02-15 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108804
           Summary: missed vectorization in presence of conversion from
                    uint64_t to float
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincenzo.innocente at cern dot ch
  Target Milestone: ---

in the following code [1] foo does not vectorize, bar doos
compiled with -march=haswell -Ofast --no-math-errno -Wall
see
https://godbolt.org/z/E6xzfavxc

clang seems do do better

[1]
#include<cstdint>



uint64_t d[512];
//uint32_t f[1024];
float f[1024];

void foo() {
    for (int i=0; i<512; ++i) {
        uint64_t k = d[i];
        auto x  = (k & 0x007FFFFF) |  0x3F800000;
        k = k >> 23;
        auto y  = (k & 0x007FFFFF) |  0x3F800000;
        f[i]=x; f[128+i] = y;

    }    
}

void bar() {
    for (int i=0; i<512; ++i) {
        uint64_t k = d[i];
        uint32_t x  = (k & 0x007FFFFF);
        x |= 0x3F800000;
        uint32_t y  = k >> 23;
        y  = (y & 0x007FFFFF) |  0x3F800000;
        f[i]=x; f[128+i] = y;

    }  
}

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

* [Bug tree-optimization/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
@ 2023-02-15 20:28 ` pinskia at gcc dot gnu.org
  2023-02-15 20:30 ` [Bug target/108804] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-15 20:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  _16 = (signed long) x_10;

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

* [Bug target/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
  2023-02-15 20:28 ` [Bug tree-optimization/108804] " pinskia at gcc dot gnu.org
@ 2023-02-15 20:30 ` pinskia at gcc dot gnu.org
  2023-02-20 11:14 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-15 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |target
           Severity|normal                      |enhancement

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

* [Bug target/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
  2023-02-15 20:28 ` [Bug tree-optimization/108804] " pinskia at gcc dot gnu.org
  2023-02-15 20:30 ` [Bug target/108804] " pinskia at gcc dot gnu.org
@ 2023-02-20 11:14 ` rguenth at gcc dot gnu.org
  2023-02-21  0:54 ` crazylht at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-20 11:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2023-02-20

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
EVRP does

@@ -38,16 +61,18 @@
   k_12 = k_10 >> 23;
   _2 = k_12 & 8388607;
   y_13 = _2 | 1065353216;
-  _3 = (float) x_11;
+  _17 = (signed long) x_11;
+  _3 = (float) _17;
   f[i_6] = _3;
   _4 = i_6 + 128;
-  _5 = (float) y_13;
+  _18 = (signed long) y_13;
+  _5 = (float) _18;
   f[_4] = _5;

because unsigned long -> float is even more difficult.  With -fno-tree-vrp
the conversion is still from uint64_t but that's not supported either.

So it's a target issue.  Shorter testcase:

#include<stdint.h>

uint64_t d[512];
float f[1024];

void foo() {
    for (int i=0; i<512; ++i) {
        uint64_t k = d[i];
        f[i]=k;
    }
}

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

* [Bug target/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
                   ` (2 preceding siblings ...)
  2023-02-20 11:14 ` rguenth at gcc dot gnu.org
@ 2023-02-21  0:54 ` crazylht at gmail dot com
  2023-03-09  5:52 ` crazylht at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2023-02-21  0:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
I think the point here is: although it's unit64_t -> float, but the range of x
and y can be represent as int32(k & 0x007FFFFF) |  0x3F800000), so we can use
int32 -> float instructions which are supported by the backend.

So it looks to me a middle-end issue.

A simple testcase clang generates vcvtdq2ps but gcc doesn't vectorize.

#include<stdint.h>

uint64_t d[512];
float f[1024];

void foo() {
    for (int i=0; i<512; ++i) {
        uint64_t k = d[i];
        f[i]=(k & 0x3F30FFFF);
    }
}

manually add convertion then gcc also can do vectorization.

#include<stdint.h>

uint64_t d[512];
float f[1024];

void foo() {
    for (int i=0; i<512; ++i) {
        uint64_t k = d[i];
        f[i]=(int)(k & 0x3F30FFFF);
    }
}

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

* [Bug target/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
                   ` (3 preceding siblings ...)
  2023-02-21  0:54 ` crazylht at gmail dot com
@ 2023-03-09  5:52 ` crazylht at gmail dot com
  2023-05-30 23:18 ` cvs-commit at gcc dot gnu.org
  2023-05-30 23:18 ` crazylht at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2023-03-09  5:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Hongtao.liu <crazylht at gmail dot com> ---
Created attachment 54613
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54613&action=edit
Patch pending for GCC14

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

* [Bug target/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
                   ` (4 preceding siblings ...)
  2023-03-09  5:52 ` crazylht at gmail dot com
@ 2023-05-30 23:18 ` cvs-commit at gcc dot gnu.org
  2023-05-30 23:18 ` crazylht at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-30 23:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:3279b6223066d36d2e6880a137f80a46d3c82c8f

commit r14-1421-g3279b6223066d36d2e6880a137f80a46d3c82c8f
Author: liuhongt <hongtao.liu@intel.com>
Date:   Wed Feb 22 17:54:46 2023 +0800

    Enhance NARROW FLOAT_EXPR vectorization by truncating integer to lower
precision.

    Similar like WIDEN FLOAT_EXPR, when direct_optab is not existed, try
    intermediate integer type whenever gimple ranger can tell it's safe.

    .i.e.
    When there's no direct optab for vector long long -> vector float, but
    the value range of integer can be represented as int, try vector int
    -> vector float if availble.

    gcc/ChangeLog:

            PR tree-optimization/108804
            * tree-vect-patterns.cc (vect_get_range_info): Remove static.
            * tree-vect-stmts.cc (vect_create_vectorized_demotion_stmts):
            Add new parameter narrow_src_p.
            (vectorizable_conversion): Enhance NARROW FLOAT_EXPR
            vectorization by truncating to lower precision.
            * tree-vectorizer.h (vect_get_range_info): New declare.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr108804.c: New test.

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

* [Bug target/108804] missed vectorization in presence of conversion from uint64_t to float
  2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
                   ` (5 preceding siblings ...)
  2023-05-30 23:18 ` cvs-commit at gcc dot gnu.org
@ 2023-05-30 23:18 ` crazylht at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2023-05-30 23:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Hongtao.liu <crazylht at gmail dot com> ---
Fixed for GCC14.

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

end of thread, other threads:[~2023-05-30 23:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 14:16 [Bug tree-optimization/108804] New: missed vectorization in presence of conversion from uint64_t to float vincenzo.innocente at cern dot ch
2023-02-15 20:28 ` [Bug tree-optimization/108804] " pinskia at gcc dot gnu.org
2023-02-15 20:30 ` [Bug target/108804] " pinskia at gcc dot gnu.org
2023-02-20 11:14 ` rguenth at gcc dot gnu.org
2023-02-21  0:54 ` crazylht at gmail dot com
2023-03-09  5:52 ` crazylht at gmail dot com
2023-05-30 23:18 ` cvs-commit at gcc dot gnu.org
2023-05-30 23:18 ` 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).