ppc64le: possible SIMD issue casting double to int
Host environment
- Operating system: Debian 11 "bullseye"
- OS/kernel version: 5.15.0-0.bpo.2-amd64
- Architecture: x86_64
- QEMU flavor: qemu-system-ppc64le
- QEMU version: 6.1.0
- QEMU command line:
qemu-system-ppc64le test.img
Emulated/Virtualized environment
- Operating system: Debian unstable "sid"
- OS/kernel version: 5.15.0-3-powerpc64le
- Architecture: ppc64le
Description of problem
Working with numpy in a ppc64le VM, I ran into a strange double -to casting issue, specifically when casting an array of 1.0 values to 1 values. The numpy folks guided me to a small reproducible test case.
The attached convert.c creates double and int arrays of length 1 <= n <= 16
. The double array is filled with the value 1.0, and both arrays are passed to a function that converts the value.
With -O2
, output is as expected (truncated here):
i = 1: 1
i = 2: 1 1
i = 3: 1 1 1
i = 4: 1 1 1 1
i = 5: 1 1 1 1 1
i = 6: 1 1 1 1 1 1
With -O3
, all values that fit into blocks of four become zero:
i = 1: 1
i = 2: 1 1
i = 3: 1 1 1
i = 4: 0 0 0 0
i = 5: 0 0 0 0 1
i = 6: 0 0 0 0 1 1
I tested this with executables compiled on a physical ppc64le host, where the issue is not reproducible.
Steps to reproduce
gcc -O2 -o convert convert.c && ./convert
gcc -O3 -o convert convert.c && ./convert