From 703cf0424b3cff4565af76402a98b883ced9e25c Mon Sep 17 00:00:00 2001 From: Chenghui Pan Date: Sat, 27 Jan 2024 14:13:06 +0800 Subject: [PATCH] LoongArch: Fixing ICE when returning struct with more than 2 vector member. 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. --- gcc/config/loongarch/loongarch.cc | 14 ++++++-------- .../vector/lasx/vect-abi-ret-struct-7.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/vector/lasx/vect-abi-ret-struct-7.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 714929b83d77a..d1946fb4c02b0 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -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)) @@ -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; diff --git a/gcc/testsuite/gcc.target/loongarch/vector/lasx/vect-abi-ret-struct-7.c b/gcc/testsuite/gcc.target/loongarch/vector/lasx/vect-abi-ret-struct-7.c new file mode 100644 index 0000000000000..80c5f4d2478df --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/vector/lasx/vect-abi-ret-struct-7.c @@ -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; +}