https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116274
Bug ID: 116274 Summary: x86: poor code generation with 16 byte function arguments Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ripatel at wii dot dev Target Milestone: --- The following program: struct a { long x,y; }; long test(struct a a) { return a.x+a.y; } compiled with $ gcc -c -o test.o -march=x86-64-v2 -O3 test.c Results in 15 x86_64 instructions using xmm registers when using the System V calling convention, when it should be two (lea, ret). $ objdump -d test.o test.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <test>: 0: 0f 29 4c 24 e8 movaps %xmm1,-0x18(%rsp) 5: 48 8b 54 24 f0 mov -0x10(%rsp),%rdx a: 66 48 0f 6e cf movq %rdi,%xmm1 f: 66 48 0f 6e de movq %rsi,%xmm3 14: 66 48 0f 3a 22 ca 01 pinsrq $0x1,%rdx,%xmm1 1b: 66 0f 6c cb punpcklqdq %xmm3,%xmm1 1f: 0f 29 4c 24 e8 movaps %xmm1,-0x18(%rsp) 24: 48 8b 44 24 f0 mov -0x10(%rsp),%rax 29: 66 0f 6f d1 movdqa %xmm1,%xmm2 2d: 66 48 0f 3a 22 d0 01 pinsrq $0x1,%rax,%xmm2 34: 66 0f 6f c2 movdqa %xmm2,%xmm0 38: 66 0f 73 d8 08 psrldq $0x8,%xmm0 3d: 66 0f d4 c1 paddq %xmm1,%xmm0 41: 66 48 0f 7e c0 movq %xmm0,%rax 46: c3 Debug information: $ gcc -v -save-temps -c -o test.o -march=x86-64-v2 -O3 test.c Using built-in specs. COLLECT_GCC=gcc OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-14.2.1-20240801/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.2.1 20240801 (Red Hat 14.2.1-1) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-o' 'test.o' '-march=x86-64-v2' '-O3' /usr/libexec/gcc/x86_64-redhat-linux/14/cc1 -E -quiet -v test.c -march=x86-64-v2 -O3 -fpch-preprocess -o test.i ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/14/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-redhat-linux/14/include /usr/local/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-o' 'test.o' '-march=x86-64-v2' '-O3' /usr/libexec/gcc/x86_64-redhat-linux/14/cc1 -fpreprocessed test.i -quiet -dumpbase test.c -dumpbase-ext .c -march=x86-64-v2 -O3 -version -o test.s GNU C17 (GCC) version 14.2.1 20240801 (Red Hat 14.2.1-1) (x86_64-redhat-linux) compiled by GNU C version 14.2.1 20240801 (Red Hat 14.2.1-1), GMP version 6.2.1, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 7983ab47815232989bed61515b77d1c7 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-o' 'test.o' '-march=x86-64-v2' '-O3' as -v --64 -o test.o test.s GNU assembler version 2.41 (x86_64-redhat-linux) using BFD version version 2.41-37.fc40 COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/14/:/usr/libexec/gcc/x86_64-redhat-linux/14/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/14/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/14/:/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/14/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-o' 'test.o' '-march=x86-64-v2' '-O3' '-dumpdir' 'test.'