Skip to content

Commit

Permalink
LoongArch: Fixing ICE when returning struct with more than 2 vector m…
Browse files Browse the repository at this point in the history
…ember.

This patch fixes the wrong-placed condition inside loongarch_flatten_aggregate_field ()
function, which causes the ICE.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_flatten_aggregate_field):
	Fixing ICE when returning struct with more than 2 vector member.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/vector/lasx/vect-abi-ret-struct-7.c: New test.
  • Loading branch information
ChenghuiPan committed Jan 27, 2024
1 parent 84e74e7 commit 703cf04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
14 changes: 6 additions & 8 deletions gcc/config/loongarch/loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,11 @@ loongarch_flatten_aggregate_field (const_tree type,
&& GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_LSX_REG;
bool lasx_p = LASX_SUPPORTED_MODE_P (TYPE_MODE (type))
&& GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_LASX_REG;
bool vec_flatten_p = (VECTOR_TYPE_P (type)
&& pcs == LA_PCS_SIMD
bool flatten_p = ((SCALAR_FLOAT_TYPE_P (type)
&& GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FP_ARG)
|| (INTEGRAL_TYPE_P (type)
&& GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_WORD));
bool vec_flatten_p = (VECTOR_TYPE_P (type) && pcs == LA_PCS_SIMD
&& (lsx_p || lasx_p));

switch (TREE_CODE (type))
Expand Down Expand Up @@ -496,12 +499,7 @@ loongarch_flatten_aggregate_field (const_tree type,
}

default:
if ((n < 2
&& ((SCALAR_FLOAT_TYPE_P (type)
&& GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FP_ARG)
|| (INTEGRAL_TYPE_P (type)
&& GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_WORD)))
|| vec_flatten_p)
if (n < 2 && (flatten_p || vec_flatten_p))
{
fields[n].type = type;
fields[n].offset = offset;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* { dg-do compile } */
/* { dg-options "-O2 -mvecarg -mabi=lp64d -Wno-strict-aliasing" } */

typedef double __m256d __attribute__ ((__vector_size__ (32),
__may_alias__));

typedef struct {
__m256d x, y, z;
} __m256dx3;

__m256dx3
foo(__m256d x, __m256d y, __m256d z)
{
__m256dx3 v = { x, y, z };
return v;
}

0 comments on commit 703cf04

Please sign in to comment.