simde icon indicating copy to clipboard operation
simde copied to clipboard

neon/qabs/vqabsq_s32 non-SSE2/native error with Debian clang version 11.0.1-2 ; amd64/arm64/armhf

Open mr-c opened this issue 2 years ago • 10 comments

[1773/3004] clang -Itest/arm/neon/qabs-native-c.p -Itest/arm/neon -I../test/arm/neon -I. -I.. -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -g -O2 '-ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=.' -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fopenmp-simd -DSIMDE_CONSTRAINED_COMPILATION -DSIMDE_ENABLE_OPENMP -Wno-psabi -DSIMDE_TEST_BARE -MD -MQ test/arm/neon/qabs-native-c.p/qabs.c.o -MF test/arm/neon/qabs-native-c.p/qabs.c.o.d -o test/arm/neon/qabs-native-c.p/qabs.c.o -c ../test/arm/neon/qabs.c

not ok 11 qabs/vqabsq_s32
ok 12 qabs/vqabsq_s64
--- stderr ---
../test/arm/neon/qabs.c:520: assertion failed: r[0] == simde_vld1q_s32(test_vec[i].r)[0] (-2147483648 == 2147483647)
CC=clang CXX=clang++ dh_auto_configure --builddirectory=clang_test
	cd clang_test && LC_ALL=C.UTF-8 meson .. --wrap-mode=nodownload --buildtype=plain --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=lib/x86_64-linux-gnu
The Meson build system
Version: 0.56.2
Source dir: /build/simde-0.7.3~0git20210814191010.3f186a0
Build dir: /build/simde-0.7.3~0git20210814191010.3f186a0/clang_test
Build type: native build
Project name: SIMDe
Project version: 0.7.3
Using 'CC' from environment with value: 'clang'
Using 'CFLAGS' from environment with value: '-g -O2 -ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=. -fstack-protector-strong -Wformat -Werror=format-security'
Using 'LDFLAGS' from environment with value: '-Wl,-z,relro -Wl,-z,now'
Using 'CPPFLAGS' from environment with value: '-Wdate-time -D_FORTIFY_SOURCE=2'
C compiler for the host machine: clang (clang 11.0.1-2 "Debian clang version 11.0.1-2")
C linker for the host machine: clang ld.bfd 2.37
Using 'CXX' from environment with value: 'clang++'
Using 'CXXFLAGS' from environment with value: '-g -O2 -ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=. -fstack-protector-strong -Wformat -Werror=format-security'
Using 'LDFLAGS' from environment with value: '-Wl,-z,relro -Wl,-z,now'
Using 'CPPFLAGS' from environment with value: '-Wdate-time -D_FORTIFY_SOURCE=2'
C++ compiler for the host machine: clang++ (clang 11.0.1-2 "Debian clang version 11.0.1-2")
C++ linker for the host machine: clang++ ld.bfd 2.37
Using 'CC' from environment with value: 'clang'
Using 'CFLAGS' from environment with value: '-g -O2 -ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=. -fstack-protector-strong -Wformat -Werror=format-security'
Using 'LDFLAGS' from environment with value: '-Wl,-z,relro -Wl,-z,now'
Using 'CPPFLAGS' from environment with value: '-Wdate-time -D_FORTIFY_SOURCE=2'
Using 'CXX' from environment with value: 'clang++'
Using 'CXXFLAGS' from environment with value: '-g -O2 -ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=. -fstack-protector-strong -Wformat -Werror=format-security'
Using 'LDFLAGS' from environment with value: '-Wl,-z,relro -Wl,-z,now'
Using 'CPPFLAGS' from environment with value: '-Wdate-time -D_FORTIFY_SOURCE=2'
Host machine cpu family: x86_64
Host machine cpu: x86_64
Library m found: YES
Compiler for C supports arguments -fopenmp-simd: YES 
Compiler for C++ supports arguments -fopenmp-simd: YES 
Compiler for C supports arguments -Wpsabi: YES 
Compiler for C++ supports arguments -Wpsabi: YES 
Library m found: YES
Build targets in project: 1502

mr-c avatar Aug 16 '21 16:08 mr-c

edit: nevermind.

__m128i sse2_abs_sat_s8(__m128i a) {
	__m128i m = _mm_cmpgt_epi8(_mm_setzero_si128(), a);
	a = _mm_xor_si128(a, m);
	return _mm_subs_epi8(a, m);
}

aqrit avatar Aug 16 '21 21:08 aqrit

__m128i sse2_abs_sat_s32(__m128i a) {
	__m128i m = _mm_srai_epi32(a, 31);
	a = _mm_xor_si128(a, m);
	a = _mm_sub_epi32(a, m);
	m = _mm_srai_epi32(a, 31);
	return _mm_xor_si128(a, m);
}

aqrit avatar Aug 16 '21 21:08 aqrit

Oops, I pasted the wrong compilation logs, it is the emul version that fails, not the native version

Summary of Failures:

 875/1502 arm/neon/qabs/emul/c                    ERROR          0.01s
 877/1502 arm/neon/qabs/emul/cpp                  ERROR          0.01s

Ok:                 1500
Expected Fail:      0
Fail:               2
Unexpected Pass:    0
Skipped:            0
Timeout:            0
[1770/3004] clang -Itest/arm/neon/qabs-emul-c.p -Itest/arm/neon -I../test/arm/neon -I. -I.. -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -g -O2 '-ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=.' -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fopenmp-simd -DSIMDE_CONSTRAINED_COMPILATION -DSIMDE_ENABLE_OPENMP -Wno-psabi -DSIMDE_TEST_BARE -DSIMDE_NO_NATIVE -MD -MQ test/arm/neon/qabs-emul-c.p/qabs.c.o -MF test/arm/neon/qabs-emul-c.p/qabs.c.o.d -o test/arm/neon/qabs-emul-c.p/qabs.c.o -c ../test/arm/neon/qabs.c
[1771/3004] clang  -o test/arm/neon/qabs-emul-c test/arm/neon/qabs-emul-c.p/qabs.c.o -Wl,--as-needed -Wl,--no-undefined -g -O2 '-ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=.' -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wl,-z,now -Wl,--start-group -lm -Wl,--end-group

[1781/3004] clang++ -Itest/arm/neon/qabs-emul-cpp.p -Itest/arm/neon -I../test/arm/neon -I. -I.. -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -g -O2 '-ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=.' -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fopenmp-simd -DSIMDE_CONSTRAINED_COMPILATION -DSIMDE_ENABLE_OPENMP -Wno-psabi -DSIMDE_TEST_BARE -DSIMDE_NO_NATIVE -MD -MQ test/arm/neon/qabs-emul-cpp.p/meson-generated_.._qabs.cpp.o -MF test/arm/neon/qabs-emul-cpp.p/meson-generated_.._qabs.cpp.o.d -o test/arm/neon/qabs-emul-cpp.p/meson-generated_.._qabs.cpp.o -c test/arm/neon/qabs.cpp
[1782/3004] clang++  -o test/arm/neon/qabs-emul-cpp test/arm/neon/qabs-emul-cpp.p/meson-generated_.._qabs.cpp.o -Wl,--as-needed -Wl,--no-undefined -g -O2 '-ffile-prefix-map=/build/simde-0.7.3~0git20210814191010.3f186a0=.' -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wl,-z,now -Wl,--start-group -lm -Wl,--end-group

mr-c avatar Aug 17 '21 07:08 mr-c

another uninformed flyby: Suppose the negation of INT_MIN is UB? Thus the compiler assumes it never happens, and precedes to optimizes away the INT_MIN stuff after the call to abs().

aqrit avatar Aug 18 '21 19:08 aqrit

I can confirm that casting to unsigned in simde_vabsq_s32 before negating does cause the failing tests to pass. I'll create a patch sometime in the next couple of days.

Probably have to change -a_.values to UINT32_C(0) - (uint32_t)a_.values for all widths.

The test failure can be reproduced by...

Install Debian 11 in a VM:

qemu-img create -f qcow2 hd.qcow2 5G 
qemu-system-x86_64 -cdrom debian-11.0.0-amd64-netinst.iso -cpu host -enable-kvm -m 2048 -smp 2 -drive file=hd.qcow2,format=qcow2

Then executing the following commands in the VM:

su -
apt install debhelper clang-11 ninja-build meson -y
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-11 1001
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-11 1001
exit

wget -c https://salsa.debian.org/med-team/simde/-/archive/debian/experimental/simde-debian-experimental.tar.gz
tar -xf simde-debian-experimental.tar.gz

cd simde-debian-experimental
CC=clang CXX=clang++ dh_auto_configure --builddirectory=clang_test 
cd clang_test 
ninja test/arm/neon/qabs-emul-c
./test/arm/neon/qabs-emul-c

After grabbing the clang_test folder out of the VM. I was able to reproduce the issue on simde-master using the clang-12 package on Ubuntu.

aqrit avatar Aug 30 '21 19:08 aqrit

Undefined behavior stemming from signed overflow seems to be everywhere. At this time, I'd say that SIMDE should never be used without -fwrapv.

😢

aqrit avatar Sep 01 '21 19:09 aqrit

@aqrit could you open a PR with your patches?

mr-c avatar Oct 13 '21 09:10 mr-c

Removing from the 0.8.0 milestone as this is clang-only.

mr-c avatar Oct 13 '21 11:10 mr-c

It seems I faced this issue on clang 15.0.7 + -O2 flag on simde v0.7.4-rc1 on Fedora rawhide (= Fedora 39)

+ _time meson test -C build/clang-O2 -q --no-rebuild --print-errorlogs
+ /usr/bin/time -f '=> [%E]' meson test -C build/clang-O2 -q --no-rebuild --print-errorlogs
▶  897/1534 qabs/vqabsq_s32                       FAIL          
 897/1534 arm/neon/qabs/emul/c                    ERROR           0.06s   exit status 1
>>> MALLOC_PERTURB_=80 /builddir/build/BUILD/simde-9609eb2cf687984277185813fdfe81b8b200377b/build/clang-O2/test/arm/neon/qabs-emul-c
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
stderr:
../../test/arm/neon/qabs.c:520: assertion failed: r[0] == simde_vld1q_s32(test_vec[i].r)[0] (-2147483648 == 2147483647)
(test program exited with status code 1)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Unknown TAP version. The first line MUST be `TAP version <int>`. Assuming version 12.
▶  905/1534 qabs/vqabsq_s32                       FAIL          
 905/1534 arm/neon/qabs/emul/cpp                  ERROR           0.08s   exit status 1
>>> MALLOC_PERTURB_=141 /builddir/build/BUILD/simde-9609eb2cf687984277185813fdfe81b8b200377b/build/clang-O2/test/arm/neon/qabs-emul-cpp
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
stderr:
test/arm/neon/qabs.cpp:520: assertion failed: r[0] == simde_vld1q_s32(test_vec[i].r)[0] (-2147483648 == 2147483647)
(test program exited with status code 1)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Unknown TAP version. The first line MUST be `TAP version <int>`. Assuming version 12.
Summary of Failures:
 897/1534 arm/neon/qabs/emul/c                    ERROR           0.06s   exit status 1
 905/1534 arm/neon/qabs/emul/cpp                  ERROR           0.08s   exit status 1
Ok:                 1532
Expected Fail:      0   
Fail:               2   
Unexpected Pass:    0   
Skipped:            0   
Timeout:            0   

junaruga avatar Feb 09 '23 20:02 junaruga

To reproduce, edit docker/cross-files/clang-11 and add -O2 to the flags and

cd docker
./simde-dev.sh
# now inside the container
simde-reset-build.sh clang-11
meson compile -C clang-11
meson test -C clang11 --print-errorlogs

Confirmed with https://github.com/simd-everywhere/simde/releases/tag/v0.7.4-rc3

mr-c avatar Apr 29 '23 11:04 mr-c