public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc at kheafield dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/94832] New: AVX512 scatter/gather macros lack parentheses when unoptimized
Date: Tue, 28 Apr 2020 19:50:21 +0000	[thread overview]
Message-ID: <bug-94832-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 94832
           Summary: AVX512 scatter/gather macros lack parentheses when
                    unoptimized
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at kheafield dot com
  Target Milestone: ---

This code behaves differently and produces a warning about void * arithmetic
when compiled without optimization:

#include <immintrin.h>
void Fail(int *data) {
  _mm512_mask_i32scatter_epi32(data - 1, 0xffff, _mm512_set1_epi32(1),
_mm512_set1_epi32(1), 1);
}

Warning and writes are based at (void*)data - 1:

g++ -mavx512bw example.cc -c -o example.o
In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/include/immintrin.h:55,
                 from example.cc:1:
example.cc: In function ‘void Foo(int*)’:
example.cc:4:37: warning: pointer of type ‘void *’ used in arithmetic
[-Wpointer-arith]
    4 |   _mm512_mask_i32scatter_epi32(data - 1, 0xffff, _mm512_set1_epi32(1),
_mm512_set1_epi32(1), 1);
      |                                     ^

No warning and writes are based at (void*)(data - 1), the expected behavior:

g++ -mavx512bw example.cc -O3 -c -o example.o
# No output.

If we look at avx512fintrin.h, it becomes clear why:

#ifdef __OPTIMIZE__
/* ... */
extern __inline void
__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
_mm512_mask_i32scatter_epi32 (void *__addr, __mmask16 __mask,
            __m512i __index, __m512i __v1, int __scale)
{
  __builtin_ia32_scattersiv16si (__addr, __mask, (__v16si) __index,
         (__v16si) __v1, __scale);
}
/* ... */
#else
/* ... */
#define _mm512_mask_i32scatter_epi32(ADDR, MASK, INDEX, V1, SCALE)  \
  __builtin_ia32_scattersiv16si ((void *)ADDR, (__mmask16)MASK,   \
         (__v16si)(__m512i)INDEX,   \
         (__v16si)(__m512i)V1, (int)SCALE)
/* ... */
#endif

When compiled without optimization, the header uses a macro.  And data - 1 is
mapping to (void*)data - 1, producing a warning about type ‘void *’ used in
arithmetic as well as a different address calculation.  

Tested on two gcc versions.  

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-9.3.0/work/gcc-9.3.0/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/9.3.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.3.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.3.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.3.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/include/g++-v9
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/9.3.0/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 9.3.0 p2' --disable-esp --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64
--disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp
--disable-libmudflap --disable-libssp --disable-libada --disable-systemtap
--enable-vtable-verify --enable-lto --without-isl --enable-default-pie
--enable-default-ssp
Thread model: posix
gcc version 9.3.0 (Gentoo 9.3.0 p2) 

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
8.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx
--enable-plugin --enable-default-pie --with-system-zlib
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.4.0 (Ubuntu 8.4.0-1ubuntu1~18.04)

             reply	other threads:[~2020-04-28 19:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28 19:50 gcc at kheafield dot com [this message]
2020-04-28 21:33 ` [Bug c++/94832] " jakub at gcc dot gnu.org
2020-04-29  9:45 ` [Bug target/94832] " jakub at gcc dot gnu.org
2020-04-29  9:56 ` gcc at kheafield dot com
2020-04-29 10:01 ` jakub at gcc dot gnu.org
2020-04-29 15:32 ` cvs-commit at gcc dot gnu.org
2020-04-29 15:32 ` cvs-commit at gcc dot gnu.org
2020-04-29 15:34 ` jakub at gcc dot gnu.org
2020-09-16 19:21 ` cvs-commit at gcc dot gnu.org
2020-09-16 19:21 ` cvs-commit at gcc dot gnu.org
2020-09-17 17:41 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94832-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).