public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108869] New: compiling an intrinsic wrapper : gives internal compiler error: in dwarf2out_register_main_translation_unit
@ 2023-02-21 10:08 jaydesh9 at gmail dot com
  2023-02-21 11:33 ` [Bug c/108869] " rguenth at gcc dot gnu.org
  2023-02-21 22:47 ` [Bug target/108869] " pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: jaydesh9 at gmail dot com @ 2023-02-21 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108869
           Summary: compiling an intrinsic wrapper : gives internal
                    compiler error: in
                    dwarf2out_register_main_translation_unit
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jaydesh9 at gmail dot com
  Target Milestone: ---

Hi,

I have a generically built binary that needs to include a lookup routine which
gets compiled into vectorized instructions or otherwise based upon whether the
cpu supports avx/avx2. 

The lookup routine is same as that explained here : 
https://stackoverflow.com/questions/54897297/check-all-bytes-of-a-m128i-for-a-match-of-a-single-byte-using-sse-avx-avx2 

 Here the (_mm_set1_epi8, __mm_cmpeq_epi8,_mm_movemask_epi8) intrinsic set will
compile into either vectorized instructions if avx/avx2 is supported by the cpu
or just sse based instructions, otherwise.


in a oversimplified main.c  : compiled without mavx/mavx2 and with -msse3
-msse4 -o 3

#define __SSE2__
#define SSE_Lookup() \
_mm_set1_epi8; \
__mm_cmpeq_epi8; \
match_bitmap=_mm_movemask_epi8
#endif

static inline __attribute__((always_inline))
uint64_t foo()
{
  unsigned int a=1,b,c,d;
  uint64_t match_bitmap;

  __cpuid(1,a,b,c,d);
  if(c & bit_AVX)
  {
       match_bitmap= avx_lookup();  
  }else
  {
  #if __SSE__
       SSE_Lookup();
  #endif
  }   

}

foo_avx.c

#include <emmintrin.h>

//mimicing an intrinsic wrapper
//don't want to create any new stack frames so keeping it inline

extern __inline int __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
__avx_lookup (char h, __m128i h)
{
   __m128i k = _mm_set1_epi8(h);
   __m128i r = _mm_cmpeq_epi8(k,h);
   return _mm_movemask_epi8(r);
}

GCC Bug report : Bugzilla : 

x86_64_gcc-7.5.0_glibc/bin/x86_64-openwrt-linux-gnu-gcc


Compiled as follows : 

/build/openwrt/toolchain-x86_64_gcc-7.5.0_glibc/bin/x86_64-openwrt-linux-gnu-gcc
 -fsigned-char -fmerge-constants -fPIC -pipe -MD -MP -Werror -Wall -Wextra
-Wpointer-arith -Wreturn-type -Wwrite-strings -Wno-unused-parameter
-Wunused-variable -Wno-unused-result -Wformat -Wformat-security -Winit-self
-Wno-implicit-fallthrough -Wno-format-truncation -Wno-deprecated-declarations
-Wno-error=deprecated-declarations -mtune=generic -msse3 -msse4 -mpclmul -maes
-mcx16 -g -O0 -DBUILD_UT=1 -std=gnu99 -Wno-missing-field-initializers 
-Wmissing-prototypes  -mavx -o 2 -o /build/x86_64/common/foo_avx.o foo_avx.c
foo_avx.c:19:1: internal compiler error: in
dwarf2out_register_main_translation_unit, at dwarf2out.c:26628
 }
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.openwrt.org/> for instructions.
Makefile:72: recipe for target '/build/x86_64/common/foo_avx.o' failed
make[3]: *** [/build/x86_64/common/foo_avx.o] Error 1


So question are : 
1. Is this a genuine bug ? 
2. If not, is the approach correct in defining the intrinsic wrapper 
3. Is there a better way of doing this ? goal is to have an executable with
code for sse , avx as well as avx2 avx512 embedded that can be invoked based
upon the cpu support at the run time.  

Thanks in advance.
-J

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

* [Bug c/108869] compiling an intrinsic wrapper : gives internal compiler error: in dwarf2out_register_main_translation_unit
  2023-02-21 10:08 [Bug c/108869] New: compiling an intrinsic wrapper : gives internal compiler error: in dwarf2out_register_main_translation_unit jaydesh9 at gmail dot com
@ 2023-02-21 11:33 ` rguenth at gcc dot gnu.org
  2023-02-21 22:47 ` [Bug target/108869] " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-21 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I changed the avx function to

extern __inline int __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
__avx_lookup (char kk, __m128i h)
{
   __m128i k = _mm_set1_epi8(kk);
   __m128i r = _mm_cmpeq_epi8(k,h);
   return _mm_movemask_epi8(r);
}

to make it compile but cannot reproduce with a GCC 7.5.0 native compiler on
x86_64.

Note that GCC 7.5 is no longer supported, the oldest still supported compiler
would be GCC 10.4

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

* [Bug target/108869] compiling an intrinsic wrapper : gives internal compiler error: in dwarf2out_register_main_translation_unit
  2023-02-21 10:08 [Bug c/108869] New: compiling an intrinsic wrapper : gives internal compiler error: in dwarf2out_register_main_translation_unit jaydesh9 at gmail dot com
  2023-02-21 11:33 ` [Bug c/108869] " rguenth at gcc dot gnu.org
@ 2023-02-21 22:47 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-21 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-02-21
             Status|UNCONFIRMED                 |WAITING
          Component|c                           |target

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you provide the exact preprocessed source which is causing the internal
compiler error for you? Use -save-temps or -freport-bug and attach that here?
Also since this toolchain is from openwrt, you might want to report the
internal compiler error to them as the mentioned in the error message:
See <http://bugs.openwrt.org/> for instructions.

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

end of thread, other threads:[~2023-02-21 22:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 10:08 [Bug c/108869] New: compiling an intrinsic wrapper : gives internal compiler error: in dwarf2out_register_main_translation_unit jaydesh9 at gmail dot com
2023-02-21 11:33 ` [Bug c/108869] " rguenth at gcc dot gnu.org
2023-02-21 22:47 ` [Bug target/108869] " 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).