public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* missed: not vectorized: relevant phi not supported: found_14 = PHI <found_5(7), -1(15)>
@ 2023-10-19  6:43 Mathieu Malaterre
  2023-10-19  7:17 ` Marc Glisse
  0 siblings, 1 reply; 4+ messages in thread
From: Mathieu Malaterre @ 2023-10-19  6:43 UTC (permalink / raw)
  To: gcc-help

Hi all,

After reading this SO post (*), I became curious as to what my gcc
would do with the following code. It turns out that I cannot make any
sense of the output:

% gcc -fopt-info-missed -std=c11  -O3 -c generic.c
generic.c:4:21: missed: couldn't vectorize loop
generic.c:2:5: missed: not vectorized: relevant phi not supported:
found_14 = PHI <found_5(7), 0(15)>

Doing a quick search did not reveal anything meaningful. If my
understanding is correct this is a basic information level (not meant
for GCC developers):

* https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#index-fopt-info

So my question is: what should the following sentence indicates

...
missed: not vectorized: relevant phi not supported: found_14 = PHI
<found_5(7), -1(15)>
...

For reference;

% cat generic.c
#include <stdint.h>
int hasmatch(uint16_t needle, const uint16_t haystack[4]) {
  int found = 0;
  for (int i = 0; i < 4; ++i) {
    if (needle == haystack[i]) {
      found = 1;
    }
  }
  return found;
}

(*) https://stackoverflow.com/questions/74803190/fastest-way-to-find-16bit-match-in-a-4-element-short-array

Thanks !
-- 
Mathieu

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

* Re: missed: not vectorized: relevant phi not supported: found_14 = PHI <found_5(7), -1(15)>
  2023-10-19  6:43 missed: not vectorized: relevant phi not supported: found_14 = PHI <found_5(7), -1(15)> Mathieu Malaterre
@ 2023-10-19  7:17 ` Marc Glisse
  2023-10-19  8:12   ` Mathieu Malaterre
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Glisse @ 2023-10-19  7:17 UTC (permalink / raw)
  To: Mathieu Malaterre; +Cc: gcc-help

On Thu, 19 Oct 2023, Mathieu Malaterre via Gcc-help wrote:

> After reading this SO post (*), I became curious as to what my gcc
> would do with the following code. It turns out that I cannot make any
> sense of the output:
>
> % gcc -fopt-info-missed -std=c11  -O3 -c generic.c
> generic.c:4:21: missed: couldn't vectorize loop
> generic.c:2:5: missed: not vectorized: relevant phi not supported:
> found_14 = PHI <found_5(7), 0(15)>

If you try again with a snapshot of gcc-14, it does vectorize, although 
the result doesn't seem as nice as what clang produces.
(in general I would also suggest adding -march=native or some recent arch)

> Doing a quick search did not reveal anything meaningful. If my
> understanding is correct this is a basic information level (not meant
> for GCC developers):
>
> * https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#index-fopt-info
>
> So my question is: what should the following sentence indicates
>
> ...
> missed: not vectorized: relevant phi not supported: found_14 = PHI
> <found_5(7), -1(15)>
> ...

Some information is hard to translate to a user-understandable language 
that refers to source code, this deep in the optimization, although in 
this case the message is not very informative even for a gcc dev. 
-fdump-tree-vect-details generates a file with more information, but that 
can be hard to understand if you are not used to it.

In this loop, some variables are 16 bits (haystack, needle), while the 
reduction variable is 32 bits, and gcc has a hard time vectorizing mixed 
sizes (and it doesn't realize that 'found' could be narrowed). If you 
declare 'found' as 'short' instead, something different happens.

> % cat generic.c
> #include <stdint.h>
> int hasmatch(uint16_t needle, const uint16_t haystack[4]) {
>  int found = 0;
>  for (int i = 0; i < 4; ++i) {
>    if (needle == haystack[i]) {
>      found = 1;
>    }
>  }
>  return found;
> }
>
> (*) https://stackoverflow.com/questions/74803190/fastest-way-to-find-16bit-match-in-a-4-element-short-array
>
> Thanks !

-- 
Marc Glisse

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

* Re: missed: not vectorized: relevant phi not supported: found_14 = PHI <found_5(7), -1(15)>
  2023-10-19  7:17 ` Marc Glisse
@ 2023-10-19  8:12   ` Mathieu Malaterre
  2023-10-19  8:42     ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: Mathieu Malaterre @ 2023-10-19  8:12 UTC (permalink / raw)
  To: gcc-help

Hi Marc,

On Thu, Oct 19, 2023 at 9:17 AM Marc Glisse <marc.glisse@inria.fr> wrote:
>
> On Thu, 19 Oct 2023, Mathieu Malaterre via Gcc-help wrote:
>
> > After reading this SO post (*), I became curious as to what my gcc
> > would do with the following code. It turns out that I cannot make any
> > sense of the output:
> >
> > % gcc -fopt-info-missed -std=c11  -O3 -c generic.c
> > generic.c:4:21: missed: couldn't vectorize loop
> > generic.c:2:5: missed: not vectorized: relevant phi not supported:
> > found_14 = PHI <found_5(7), 0(15)>
>
> If you try again with a snapshot of gcc-14, it does vectorize, although
> the result doesn't seem as nice as what clang produces.
> (in general I would also suggest adding -march=native or some recent arch)
>
> > Doing a quick search did not reveal anything meaningful. If my
> > understanding is correct this is a basic information level (not meant
> > for GCC developers):
> >
> > * https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#index-fopt-info
> >
> > So my question is: what should the following sentence indicates
> >
> > ...
> > missed: not vectorized: relevant phi not supported: found_14 = PHI
> > <found_5(7), -1(15)>
> > ...
>
> Some information is hard to translate to a user-understandable language
> that refers to source code, this deep in the optimization, although in
> this case the message is not very informative even for a gcc dev.
> -fdump-tree-vect-details generates a file with more information, but that
> can be hard to understand if you are not used to it.
>
> In this loop, some variables are 16 bits (haystack, needle), while the
> reduction variable is 32 bits, and gcc has a hard time vectorizing mixed
> sizes (and it doesn't realize that 'found' could be narrowed). If you
> declare 'found' as 'short' instead, something different happens.

Thanks very much for your answer, very helpful ! I was able to
vectorize a different piece of C code, just using your trick. The type
being reduced must be of the same type as the vector elements.

I still do not understand what `PHI`, `found_14` or `<found_5(7),
-1(15)>` refer to exactly, but I'll continue studying the *.vect
output.


> > % cat generic.c
> > #include <stdint.h>
> > int hasmatch(uint16_t needle, const uint16_t haystack[4]) {
> >  int found = 0;
> >  for (int i = 0; i < 4; ++i) {
> >    if (needle == haystack[i]) {
> >      found = 1;
> >    }
> >  }
> >  return found;
> > }
> >
> > (*) https://stackoverflow.com/questions/74803190/fastest-way-to-find-16bit-match-in-a-4-element-short-array
> >
> > Thanks !
>
> --
> Marc Glisse



--
Mathieu

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

* Re: missed: not vectorized: relevant phi not supported: found_14 = PHI <found_5(7), -1(15)>
  2023-10-19  8:12   ` Mathieu Malaterre
@ 2023-10-19  8:42     ` Andrew Haley
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2023-10-19  8:42 UTC (permalink / raw)
  To: gcc-help

On 10/19/23 09:12, Mathieu Malaterre via Gcc-help wrote:
> I still do not understand what `PHI`, `found_14` or `<found_5(7), -1(15)>`
> refer to exactly, but I'll continue studying the *.vect output.

Phi nodes:
https://en.wikipedia.org/wiki/Static_single-assignment_form#Converting_to_SSA

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


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

end of thread, other threads:[~2023-10-19  8:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19  6:43 missed: not vectorized: relevant phi not supported: found_14 = PHI <found_5(7), -1(15)> Mathieu Malaterre
2023-10-19  7:17 ` Marc Glisse
2023-10-19  8:12   ` Mathieu Malaterre
2023-10-19  8:42     ` Andrew Haley

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