public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes
@ 2021-02-02  7:19 gabravier at gmail dot com
  2021-02-02  8:22 ` [Bug target/98927] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2021-02-02  7:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98927
           Summary: Code using _mm_extract_epi16 compiles with -O3 but not
                    on other optimization modes
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

#include <stdint.h>
#include <x86intrin.h>

void f(int16_t *out, __m128i packed)
{
    for (unsigned i = 0; i < 8; i++)
        out[i] = _mm_extract_epi16(packed, i);
}

This compiles with -O3, but fails on -O2 and below with this message:

In file included from
/opt/compiler-explorer/gcc-trunk-20210202/lib/gcc/x86_64-linux-gnu/11.0.0/include/xmmintrin.h:1316,
                 from
/opt/compiler-explorer/gcc-trunk-20210202/lib/gcc/x86_64-linux-gnu/11.0.0/include/immintrin.h:31,
                 from
/opt/compiler-explorer/gcc-trunk-20210202/lib/gcc/x86_64-linux-gnu/11.0.0/include/x86intrin.h:32,
                 from <source>:2:
/opt/compiler-explorer/gcc-trunk-20210202/lib/gcc/x86_64-linux-gnu/11.0.0/include/emmintrin.h:
In function 'void f(int16_t*, __m128i)':
/opt/compiler-explorer/gcc-trunk-20210202/lib/gcc/x86_64-linux-gnu/11.0.0/include/emmintrin.h:1391:55:
error: selector must be an integer constant in the range [0, 7]
 1391 |   return (unsigned short) __builtin_ia32_vec_ext_v8hi ((__v8hi)__A,
__N);
      |                          
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
Compiler returned: 1

Is this intended behaviour ? It seems odd to make it valid to have code rely on
loop unrolling for it to compile at all.

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

* [Bug target/98927] Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes
  2021-02-02  7:19 [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes gabravier at gmail dot com
@ 2021-02-02  8:22 ` rguenth at gcc dot gnu.org
  2021-02-02  8:50 ` crazylht at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-02  8:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Well, I guess it's a missed diagnostic at -O3.  Basically we try to support
thin wrappers where inlining would expose a constant.  Guess we might want to
diagnose in non-always-inline context.

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

* [Bug target/98927] Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes
  2021-02-02  7:19 [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes gabravier at gmail dot com
  2021-02-02  8:22 ` [Bug target/98927] " rguenth at gcc dot gnu.org
@ 2021-02-02  8:50 ` crazylht at gmail dot com
  2021-02-02 20:32 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: crazylht at gmail dot com @ 2021-02-02  8:50 UTC (permalink / raw)
  To: gcc-bugs

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

Hongtao.liu <crazylht at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crazylht at gmail dot com

--- Comment #2 from Hongtao.liu <crazylht at gmail dot com> ---
The second parameter of _mm_extract_epi16 only accept constants, O3 didn't
report this error because the loop is completed unrolled, and the code to check
is in pass_expand, which is after tree unroll.

  _15 = VIEW_CONVERT_EXPR<vector(8) short int>(packed_8(D));
  _5 = __builtin_ia32_vec_ext_v8hi (_15, 0);
  _31 = __builtin_ia32_vec_ext_v8hi (_15, 1);
  _42 = __builtin_ia32_vec_ext_v8hi (_15, 2);
  _53 = __builtin_ia32_vec_ext_v8hi (_15, 3);
  _64 = __builtin_ia32_vec_ext_v8hi (_15, 4);
  _75 = __builtin_ia32_vec_ext_v8hi (_15, 5);
  _86 = __builtin_ia32_vec_ext_v8hi (_15, 6);
  _13 = __builtin_ia32_vec_ext_v8hi (_15, 7);

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

* [Bug target/98927] Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes
  2021-02-02  7:19 [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes gabravier at gmail dot com
  2021-02-02  8:22 ` [Bug target/98927] " rguenth at gcc dot gnu.org
  2021-02-02  8:50 ` crazylht at gmail dot com
@ 2021-02-02 20:32 ` jakub at gcc dot gnu.org
  2021-02-03 21:34 ` pinskia at gcc dot gnu.org
  2021-08-17  9:30 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-02-02 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As we use inline functions, it is required to diagnose this only after
inlining, and historically we've been doing that during expansion, so that even
if a constant materializes through optimizations it is accepted.
I think not diagnosing this when the loop is unrolled and only constants make
it in is just fine.

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

* [Bug target/98927] Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes
  2021-02-02  7:19 [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2021-02-02 20:32 ` jakub at gcc dot gnu.org
@ 2021-02-03 21:34 ` pinskia at gcc dot gnu.org
  2021-08-17  9:30 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-02-03 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This issue has come up for both Altivec/VMX (RS6000) and ARM/AARCH64 intrinsics
before.  I think they both came up slightly different solutions. I can't
remember fully what the solutions were but from what I recall one decided this
was acceptable behavior and said the documentation for these intrinsics
supported that (I am not 100% sure though).

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

* [Bug target/98927] Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes
  2021-02-02  7:19 [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-02-03 21:34 ` pinskia at gcc dot gnu.org
@ 2021-08-17  9:30 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  9:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Seems like ARM is going down the route of requiring the arugments to be
"constexpr" like. 

See https://gcc.gnu.org/pipermail/gcc/2021-August/236960.html (and all of the
related threads).

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

end of thread, other threads:[~2021-08-17  9:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02  7:19 [Bug target/98927] New: Code using _mm_extract_epi16 compiles with -O3 but not on other optimization modes gabravier at gmail dot com
2021-02-02  8:22 ` [Bug target/98927] " rguenth at gcc dot gnu.org
2021-02-02  8:50 ` crazylht at gmail dot com
2021-02-02 20:32 ` jakub at gcc dot gnu.org
2021-02-03 21:34 ` pinskia at gcc dot gnu.org
2021-08-17  9:30 ` 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).