Bug 60204 - struct with __m512i is mishandled in function parameter passing and return
Summary: struct with __m512i is mishandled in function parameter passing and return
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.0
: P3 major
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: ABI, wrong-code
Depends on:
Blocks:
 
Reported: 2014-02-14 20:26 UTC by H.J. Lu
Modified: 2014-02-20 13:17 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-02-18 00:00:00


Attachments
Proposed patch. (1.09 KB, patch)
2014-02-19 11:03 UTC, tocarip.intel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2014-02-14 20:26:38 UTC
[hjl@gnu-6 avx512-1]$ cat x.i
typedef long long __m512i __attribute__ ((__vector_size__ (64), __may_alias__));

struct m512i
{
  __m512i x;
};

typedef long long __m256i __attribute__ ((__vector_size__ (32), __may_alias__));

struct m256i
{
  __m256i x;
};

struct m256i
foo1 (struct m256i x, struct m256i y, struct m256i z)
{
  return z;
}

struct m512i
foo2 (struct m512i x, struct m512i y, struct m512i z)
{
  return z;
}
[hjl@gnu-6 avx512-1]$ make
/export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -mavx512f -O2 -S x.i
[hjl@gnu-6 avx512-1]$ cat x.s
	.file	"x.i"
	.section	.text.unlikely,"ax",@progbits
.LCOLDB0:
	.text
.LHOTB0:
	.p2align 4,,15
	.globl	foo1
	.type	foo1, @function
foo1:
.LFB0:
	.cfi_startproc
	vmovdqa	%ymm2, %ymm0
	ret
	.cfi_endproc
.LFE0:
	.size	foo1, .-foo1
	.section	.text.unlikely
.LCOLDE0:
	.text
.LHOTE0:
	.section	.text.unlikely
.LCOLDB1:
	.text
.LHOTB1:
	.p2align 4,,15
	.globl	foo2
	.type	foo2, @function
foo2:
.LFB1:
	.cfi_startproc
	vmovdqa64	136(%rsp), %zmm0
	movq	%rdi, %rax
	vmovdqa64	%zmm0, (%rdi)
	ret
	.cfi_endproc
.LFE1:
	.size	foo2, .-foo2
	.section	.text.unlikely
.LCOLDE1:
	.text
.LHOTE1:
	.ident	"GCC: (GNU) 4.9.0 20140214 (experimental)"
	.section	.note.GNU-stack,"",@progbits
[hjl@gnu-6 avx512-1]$ 

I am expecting struct m512i is passed/returned in zmm register per
AVX-512 extension to x86-64 psABI.
Comment 1 tocarip.intel 2014-02-18 12:26:00 UTC
From  https://github.com/hjl-tools/x86-64-psABI/blob/hjl/avx512/low-level-sys-info.tex  
\item If the size of an object is larger than four \eightbytes, or
  it contains unaligned fields, it has class MEMORY

struct m512i has size of 64 bytes, which is larger than 8*4=32, so it has class MEMORY and passed on the stack.

It looks like everything is according to ABI.
Comment 2 H.J. Lu 2014-02-18 16:54:42 UTC
(In reply to tocarip.intel from comment #1)
> From 
> https://github.com/hjl-tools/x86-64-psABI/blob/hjl/avx512/low-level-sys-info.
> tex  
> \item If the size of an object is larger than four \eightbytes, or
>   it contains unaligned fields, it has class MEMORY
> 
> struct m512i has size of 64 bytes, which is larger than 8*4=32, so it has
> class MEMORY and passed on the stack.
> 
> It looks like everything is according to ABI.

It is a bug in psABI.  It should read as "eight \eightbytes".
Comment 3 Uroš Bizjak 2014-02-19 09:48:17 UTC
(In reply to H.J. Lu from comment #2)

> It is a bug in psABI.  It should read as "eight \eightbytes".

So, let's fix the psABI first and then fix gcc.

This PR should be resolved before 4.9 is released.
Comment 4 Uroš Bizjak 2014-02-19 09:52:07 UTC
(In reply to Uroš Bizjak from comment #3)

> So, let's fix the psABI first and then fix gcc.

psABI is fixed in [1].

[1] https://github.com/hjl-tools/x86-64-psABI/commit/6d7ccd614fe67111d2aecec853c3df0310b372d2
Comment 5 tocarip.intel 2014-02-19 11:03:36 UTC
Created attachment 32169 [details]
Proposed patch.

Currently testing attached patch.
Comment 6 Kirill Yukhin 2014-02-20 06:32:53 UTC
Author: kyukhin
Date: Thu Feb 20 06:32:21 2014
New Revision: 207933

URL: http://gcc.gnu.org/viewcvs?rev=207933&root=gcc&view=rev
Log:
gcc/
	PR target/60204
	* config/i386/i386.c (classify_argument): Pass structures of size
	64 bytes or less in register.

tessuite/gcc/
	PR target/60204
	* gcc.target/x86_64/abi/avx512f/test_passing_structs.c: Update to
	reflect abi fix.
	* gcc.target/x86_64/abi/avx512f/test_passing_unions.c: Ditto.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/x86_64/abi/avx512f/test_passing_structs.c
    trunk/gcc/testsuite/gcc.target/x86_64/abi/avx512f/test_passing_unions.c
Comment 7 Uroš Bizjak 2014-02-20 13:17:07 UTC
Fixed.