public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules
@ 2023-10-13 10:31 rguenth at gcc dot gnu.org
  2023-10-13 12:02 ` [Bug tree-optimization/111796] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 10:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111796
           Summary: OMP SIMD call vectorization fails for arguments
                    subject to integer promotion rules
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

For example

int x[1024];

#pragma omp declare simd simdlen(8)
__attribute__((noinline)) int
foo (int a, short b)
{
  return a + b;
}

void __attribute__((noipa))
bar (void)
{
#pragma omp simd
  for (int i = 0; i < 1024; i++)
    x[i] = foo (x[i], x[i]);
}

fails to vetorize because for the scalar code we see

  _4 = x[i_12];
  _5 = (short int) _4;
  _6 = (int) _5;
  _7 = foo (_4, _6);

thus the second argument to 'foo' is promoted to 'int', but the SIMD clone
at least on x86_64 expects vector(8) short int simd.6 as argument.

vectorizable_simd_clone_call has the following, which will result in
rejecting the call.

        for (i = 0; i < nargs; i++)
          {
            switch (n->simdclone->args[i].arg_type)
              {
              case SIMD_CLONE_ARG_TYPE_VECTOR:
                if (!useless_type_conversion_p
                        (n->simdclone->args[i].orig_type,
                         TREE_TYPE (gimple_call_arg (stmt, i + arg_offset))))
                  i = -1;

This argument promotion is exposed by the frontend, controlled by a target
hook.  IIRC it is intended to allow more optimization, so maybe it can be
disabled for calls to OMP SIMD functions.

Alternatively the vectorizer needs to deal with this somehow, for example
in vectorizable_simd_clone_call by allowing this and instead peeking 
through the conversion.  Possibly also done via pattern recognizing the call
itself.

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
@ 2023-10-13 12:02 ` rguenth at gcc dot gnu.org
  2023-10-13 12:04 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 12:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's the promote_prototypes hook btw.

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
  2023-10-13 12:02 ` [Bug tree-optimization/111796] " rguenth at gcc dot gnu.org
@ 2023-10-13 12:04 ` rguenth at gcc dot gnu.org
  2023-10-13 12:10 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 12:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
We could also decide to only apply promote_prototype at RTL expansion time?

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
  2023-10-13 12:02 ` [Bug tree-optimization/111796] " rguenth at gcc dot gnu.org
  2023-10-13 12:04 ` rguenth at gcc dot gnu.org
@ 2023-10-13 12:10 ` rguenth at gcc dot gnu.org
  2023-10-13 12:16 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 12:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> It's the promote_prototypes hook btw.

Of the major targets (x86, arm, aarch64, powerpc, s390, riscv) only x86
defines the hook to true.  But there are a lot of embedded archs doing so,
and ia64 and the pa.

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-10-13 12:10 ` rguenth at gcc dot gnu.org
@ 2023-10-13 12:16 ` rguenth at gcc dot gnu.org
  2023-10-13 12:40 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 12:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #3)
> (In reply to Richard Biener from comment #1)
> > It's the promote_prototypes hook btw.
> 
> Of the major targets (x86, arm, aarch64, powerpc, s390, riscv) only x86
> defines the hook to true.  But there are a lot of embedded archs doing so,
> and ia64 and the pa.

Interestingly the Ada frontend has

tree
create_param_decl (tree name, tree type)
{
  tree param_decl = build_decl (input_location, PARM_DECL, name, type);

  /* Honor TARGET_PROMOTE_PROTOTYPES like the C compiler, as not doing so
     can lead to various ABI violations.  */
  if (targetm.calls.promote_prototypes (NULL_TREE)
      && INTEGRAL_TYPE_P (type)
      && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
    {
...
        type = integer_type_node;
    }
...
  DECL_ARG_TYPE (param_decl) = type;

but the hook is nowhere called in other frontends besides C, C++ and Ada.

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-10-13 12:16 ` rguenth at gcc dot gnu.org
@ 2023-10-13 12:40 ` rguenth at gcc dot gnu.org
  2023-10-13 12:45 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 12:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
On aarch64 I see

t.c:5:1: warning: GCC does not currently support mixed size types for 'simd'
functions
    5 | foo (int a, short b)
      | ^~~

simdlen(8) is also not supported, but simdlen(4) isn't diagnosed.  The above
still remains though.

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-10-13 12:40 ` rguenth at gcc dot gnu.org
@ 2023-10-13 12:45 ` rguenth at gcc dot gnu.org
  2023-11-22  5:21 ` pinskia at gcc dot gnu.org
  2023-11-24  2:09 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCN handles this fine using simdlen(64).

  <bb 3> [local count: 939524096]:
  # ivtmp.31_10 = PHI <ivtmp.31_11(3), ivtmp.31_4(2)>
  vectp_x.27_17 = (vector(64) int *) ivtmp.31_10;
  vect__4.24_14 = MEM <vector(64) int> [(int *)vectp_x.27_17];
  vect__5.25_15 = (vector(64) short int) vect__4.24_14;
  vect__6.26_16 = foo.simdclone.0 (vect__4.24_14, vect__5.25_15);
  MEM <vector(64) int> [(int *)vectp_x.27_17] = vect__6.26_16;
  ivtmp.31_11 = ivtmp.31_10 + 256;
  if (_8 != ivtmp.31_11)
    goto <bb 3>; [85.71%]

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-10-13 12:45 ` rguenth at gcc dot gnu.org
@ 2023-11-22  5:21 ` pinskia at gcc dot gnu.org
  2023-11-24  2:09 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-22  5:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-11-22
     Ever confirmed|0                           |1

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug tree-optimization/111796] OMP SIMD call vectorization fails for arguments subject to integer promotion rules
  2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-11-22  5:21 ` pinskia at gcc dot gnu.org
@ 2023-11-24  2:09 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-24  2:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #5)
> On aarch64 I see
> 
> t.c:5:1: warning: GCC does not currently support mixed size types for 'simd'
> functions
>     5 | foo (int a, short b)
>       | ^~~
> 
> simdlen(8) is also not supported, but simdlen(4) isn't diagnosed.  The above
> still remains though.

That is due to PR 96341 .

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

end of thread, other threads:[~2023-11-24  2:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-13 10:31 [Bug tree-optimization/111796] New: OMP SIMD call vectorization fails for arguments subject to integer promotion rules rguenth at gcc dot gnu.org
2023-10-13 12:02 ` [Bug tree-optimization/111796] " rguenth at gcc dot gnu.org
2023-10-13 12:04 ` rguenth at gcc dot gnu.org
2023-10-13 12:10 ` rguenth at gcc dot gnu.org
2023-10-13 12:16 ` rguenth at gcc dot gnu.org
2023-10-13 12:40 ` rguenth at gcc dot gnu.org
2023-10-13 12:45 ` rguenth at gcc dot gnu.org
2023-11-22  5:21 ` pinskia at gcc dot gnu.org
2023-11-24  2:09 ` 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).