https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85162
Bug ID: 85162 Summary: Vector extensions generating incorrect assembly Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: milesbarr2 at gmail dot com Target Milestone: --- Created attachment 43811 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43811&action=edit Preprocessed file It is possible that I am misunderstanding an undefined behaviour because this bug occurs with both GCC and Clang. In the code sample below there are two functions which should be equivalent. The compiler appears to be optimizing some valid vector comparisons out of existence as long as the pattern in the code sample is followed. This happens with vectors of all types, all sizes, and with all comparison operators (<, <=, >=, >). Code sample: typedef char V1 __attribute__ ((vector_size (1))); int check1(V1 v) { return (v > 0)[0] > 0; } typedef char V2; int check2(V2 v) { return (v > 0) > 0; } Generated assembly: _check1: LFB0: .cfi_startproc xorl %eax, %eax ret .cfi_endproc LFE0: .p2align 4,,15 .globl _check2 .def _check2; .scl 2; .type 32; .endef _check2: LFB1: .cfi_startproc xorl %eax, %eax cmpb $0, 4(%esp) setg %al ret .cfi_endproc LFE1: .def ___main; .scl 2; .type 32; .endef .section .text.startup,"x" .p2align 4,,15 .globl _main .def _main; .scl 2; .type 32; .endef I am using MinGW GCC, but I tested all the compatible versions of GCC and Clang on godbolt.org Compiler Explorer. the exact version of GCC: MinGW GCC 6.3.0 the system type: Windows 10 the options given when GCC was configured/built: N/A the complete command line that triggers the bug: gcc test.c -O2 -save-temps -S the compiler output (error messages, warnings, etc.): none the output of gcc -v: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe Target: mingw32 Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls Thread model: win32 gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)