From patchwork Fri Oct 2 19:50:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominic P X-Patchwork-Id: 145177 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2D714BA9028 for ; Fri, 2 Oct 2026 19:51:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2D714BA9028 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id B7D7E4BA23D2 for ; Fri, 2 Oct 2026 19:50:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7D7E4BA23D2 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.dp11.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B7D7E4BA23D2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790970650; cv=none; b=PSNsdAiNkBMcar979ggiC0zgL7qEUVnDx6PPxPnQHAYzjuEQA5oqXiRlZsCTEvyODw7S1VeYceAWnnLXnioBdcJT0ql0ioNqLy3KkPHZSMkM6XfXrUzMOQl9xtoUxFzEs5A3tDFmFnKsD0hr25txW2cg8QtRXHOwl9rUODO5Pcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790970650; c=relaxed/simple; bh=ytKGopFy2YbMaAKZq4ShHj985TXn+otuTBV0sPB7gBQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dbcHUcCKiMvVc6TqRbQ5jiSRs36RX6N8hAHvPBuxKGaZ/HRceV8Me9ool4wxOlgyIWsBVUP6NMP7xPoeZB7b/mrbK4p+PLRmUuWjr3xhgktuAVyOKo3K7M6ytSIKNJfTeuJ2pPZv9bd6wnBUQUo/fjHbWekie9ubNJRL9pVxjbo= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7D7E4BA23D2 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-49ff90b4b5fso1062975e9.0 for ; Fri, 02 Oct 2026 12:50:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790970649; x=1791575449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Xj5PwtanxnOmr61ie5WPyzzVWVxg0pbtbxzo0n/nbE8=; b=TV7SkQvWzyIi/o5eTnmH5veauA6Yv/eL7l9VMz0FE4mC/f8dpBXv8rlE+jjIJ++cn6 ZwgISs/RIRV0jN9skn+ATgj8zy/W9G9q7bcy6jm6A39dVPpVbyYpRbC/3Q3esHZEJ/57 nsQayAQnXFxlKOoM+RMUqBSlerPBY2qZKcfgcrUD4m4ebxvrNtIUPGC17+ZlRmyQIZyK icDRGIXzdBi7oR13RKOS46egAxBwfjE4M2NNveV9mCM9nr0gnhLzddwxH+yTtWkUs3aj U6WJ22514w08GAp36gGTdZHuAxrTTAEbmpp0K93WWtLv1zaP8q5l60w8e3BFDN0QP00G gzWQ== X-Gm-Message-State: AFuF++lvLd4226eKlr0MRUYHFGz2sCjzYKaV9LE3gl1wPtsDF7bu9OLE BejOsujJY+om2XVkbgXh6g8ODilbtHdbpXaA7J/WVS6D7QqdQaZ+su2xOBK/fNNL X-Gm-Gg: AYBFou2BmF6zLEvoMowF3yT3c9MX1Onr/kw5CatiAdHUuwCIm493zelHlatTH8Sobhw jhwU3LyfpLDx12qpWF+KHmE+rSyjJLPg6xiGwiyxYVyDdCNHJMtxkl0rqqZOGaIKP3NZl/pwJiz inEc75BTorv8ouS7WHsQRg4j03T0fgtSOagRXF3nOMFubQ/Gr1CFkXN2lkpdGdLUTIdkdwfJsow ES7tpZ/WW6GwpZAltB327cn1dykez0T9l+50mwt4a8N8G11Bk9RMQIf8HaSEzdvk4kzqyDDHAwX PlGY67cOQL08g2WC0ANp0blg7Fl9KPDYUwQV6w59nuYO8p6oc+CW8RrECUAENaKI6Bc95HEzxZ9 i7IsR+BNfYB3/3laRlcPsuJ9p79axvBTmXs7fTSVxjiw8QzPWOiAGZRHdOUsyFzcqowceVOIwvR WxC66Pp1suhXVnksvd0wJm0tUk8vVmLeg2/GyevkKQC7xg+oWu8Rx0H3TJ X-Received: by 2002:a05:600c:8596:b0:4a0:1c94:7042 with SMTP id 5b1f17b1804b1-4a1680dd3e7mr4673435e9.8.1790970649511; Fri, 02 Oct 2026 12:50:49 -0700 (PDT) Received: from tower ([185.182.54.229]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a0280be5dfsm115255135e9.7.2026.10.02.12.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 12:50:49 -0700 (PDT) From: Dominic P To: gcc-patches@gcc.gnu.org Cc: Richard Sandiford , Richard Biener , Andrea Pinski , Kito Cheng , Robin Dapp , Juzhe Zhong , Palmer Dabbelt , Tamar Christina , Kyrylo Tkachov Subject: [PATCH 2/2] expr: Clear an empty constructor of a poly-sized type [PR121105] Date: Fri, 2 Oct 2026 20:50:44 +0100 Message-ID: <20261002195044.3166661-3-gcc@gcc.dp11.uk> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261002195044.3166661-1-gcc@gcc.dp11.uk> References: <20261002195044.3166661-1-gcc@gcc.dp11.uk> MIME-Version: 1.0 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, PROLO_LEO1, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org expand_constructor passed int_expr_size to store_constructor, which is -1 for a type whose size is a POLY_INT_CST. The RECORD_TYPE case then skipped clear_storage, so an empty CONSTRUCTOR of an SVE or RVV tuple type stored nothing: a register target got only a clobber and a memory target was left unchanged. Pass the poly size instead; only types with a POLY_INT_CST size are affected. Bootstrapped and regression tested on x86_64-pc-linux-gnu. On aarch64-linux-gnu (qemu), regression tested dg.exp, aarch64.exp and the SVE tests at SVE VL128, and the SVE tests at VL2048. On riscv64, compiling gcc.target/riscv/rvv/base changes the asm of the new test only. Tested together with the previous patch and the PR123370 patch. Assisted-by: Claude Opus 5 (Anthropic) PR middle-end/121105 gcc/ChangeLog: * expr.cc (expand_constructor): Pass a poly_int64 size to store_constructor. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/pr121105_1.c: New test. * gcc.target/aarch64/sve/pr121105_2.c: New test. * g++.target/aarch64/sve/pr121105.C: New test. * gcc.target/riscv/rvv/base/pr121105.c: New test. Signed-off-by: Dominic P --- gcc/expr.cc | 5 +- .../g++.target/aarch64/sve/pr121105.C | 13 ++ .../gcc.target/aarch64/sve/pr121105_1.c | 121 ++++++++++++++++++ .../gcc.target/aarch64/sve/pr121105_2.c | 33 +++++ .../gcc.target/riscv/rvv/base/pr121105.c | 21 +++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.target/aarch64/sve/pr121105.C create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr121105_1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr121105_2.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr121105.c diff --git a/gcc/expr.cc b/gcc/expr.cc index a9157dc5d41..6f8255f2d9f 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -9573,7 +9573,10 @@ expand_constructor (tree exp, rtx target, enum expand_modifier modifier, target = assign_temp (type, TREE_ADDRESSABLE (exp), 1); } - store_constructor (exp, target, 0, int_expr_size (exp), false); + poly_int64 size; + if (!poly_int_tree_p (size_in_bytes (type), &size)) + size = -1; + store_constructor (exp, target, 0, size, false); return target; } diff --git a/gcc/testsuite/g++.target/aarch64/sve/pr121105.C b/gcc/testsuite/g++.target/aarch64/sve/pr121105.C new file mode 100644 index 00000000000..06aacb6c10a --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/pr121105.C @@ -0,0 +1,13 @@ +// PR middle-end/121105 +// { dg-do compile } +// { dg-options "-O2" } + +#include + +svfloat32x4_t +e () +{ + return svfloat32x4_t{}; +} + +// { dg-final { scan-assembler-times {\tmovi\td[0-3], #0\n} 4 } } diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr121105_1.c b/gcc/testsuite/gcc.target/aarch64/sve/pr121105_1.c new file mode 100644 index 00000000000..f508a35f526 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr121105_1.c @@ -0,0 +1,121 @@ +/* PR middle-end/121105 */ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-O2" } */ + +#include + +static int +nonzero (svuint8_t v) +{ + return svptest_any (svptrue_b8 (), svcmpne (svptrue_b8 (), v, 0)); +} + +__attribute__((noipa)) svfloat32x4_t +dirty4 (void) +{ + svfloat32_t v = svdup_f32 (-1.0f); + return svcreate4 (v, v, v, v); +} + +__attribute__((noipa)) svfloat32x4_t +ret4 (void) +{ + svfloat32x4_t x = {}; + return x; +} + +__attribute__((noipa)) svint8x2_t +ret2 (void) +{ + return (svint8x2_t) {}; +} + +__attribute__((noipa)) void +mem3 (svuint64x3_t *p) +{ + *p = (svuint64x3_t) {}; +} + +__attribute__((noipa)) void +dirty_stack (void) +{ + volatile unsigned char buf[4096]; + for (int i = 0; i < 4096; i++) + buf[i] = 0xff; +} + +__attribute__((noipa)) int +check2 (svint16x2_t *p) +{ + return (nonzero (svreinterpret_u8 (svget2 (*p, 0))) + || nonzero (svreinterpret_u8 (svget2 (*p, 1)))); +} + +__attribute__((noipa)) int +addr2 (void) +{ + svint16x2_t x = {}; + return check2 (&x); +} + +__attribute__((noipa)) svboolx4_t +dirtyb (void) +{ + svbool_t t = svptrue_b8 (); + return svcreate4 (t, t, t, t); +} + +__attribute__((noipa)) svboolx4_t +retb4 (void) +{ + return (svboolx4_t) {}; +} + +__attribute__((noipa)) void +memb2 (svboolx2_t *p) +{ + *p = (svboolx2_t) {}; +} + +int +main (void) +{ + dirty4 (); + svfloat32x4_t a = ret4 (); + if (nonzero (svreinterpret_u8 (svget4 (a, 0))) + || nonzero (svreinterpret_u8 (svget4 (a, 1))) + || nonzero (svreinterpret_u8 (svget4 (a, 2))) + || nonzero (svreinterpret_u8 (svget4 (a, 3)))) + __builtin_abort (); + + dirty4 (); + svint8x2_t b = ret2 (); + if (nonzero (svreinterpret_u8 (svget2 (b, 0))) + || nonzero (svreinterpret_u8 (svget2 (b, 1)))) + __builtin_abort (); + + svuint64_t m1 = svdup_u64 (-1); + svuint64x3_t c = svcreate3 (m1, m1, m1); + mem3 (&c); + if (nonzero (svreinterpret_u8 (svget3 (c, 0))) + || nonzero (svreinterpret_u8 (svget3 (c, 1))) + || nonzero (svreinterpret_u8 (svget3 (c, 2)))) + __builtin_abort (); + + dirty_stack (); + if (addr2 ()) + __builtin_abort (); + + svbool_t all = svptrue_b8 (); + dirtyb (); + svboolx4_t d = retb4 (); + if (svptest_any (all, svget4 (d, 0)) || svptest_any (all, svget4 (d, 1)) + || svptest_any (all, svget4 (d, 2)) || svptest_any (all, svget4 (d, 3))) + __builtin_abort (); + + svboolx2_t e = svcreate2 (all, all); + memb2 (&e); + if (svptest_any (all, svget2 (e, 0)) || svptest_any (all, svget2 (e, 1))) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr121105_2.c b/gcc/testsuite/gcc.target/aarch64/sve/pr121105_2.c new file mode 100644 index 00000000000..1c50e31422f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr121105_2.c @@ -0,0 +1,33 @@ +/* PR middle-end/121105 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include + +svboolx2_t +ret2 (void) +{ + svboolx2_t x = {}; + return x; +} + +svboolx4_t +ret4 (void) +{ + return (svboolx4_t) {}; +} + +void +mem2 (svboolx2_t *p) +{ + *p = (svboolx2_t) {}; +} + +void +mem4 (svboolx4_t *p) +{ + *p = (svboolx4_t) {}; +} + +/* { dg-final { scan-assembler-times {\tpfalse\tp[0-9]+\.b\n} 12 } } */ +/* { dg-final { scan-assembler-times {\tstr\tp[0-9]+, \[x0(?:, #[1-3], mul vl)?\]\n} 6 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr121105.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr121105.c new file mode 100644 index 00000000000..118d4f04ed3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr121105.c @@ -0,0 +1,21 @@ +/* PR middle-end/121105 */ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O2" } */ + +#include "riscv_vector.h" + +vint32m1x4_t +ret4 (void) +{ + vint32m1x4_t x = {}; + return x; +} + +void +mem2 (vint8m1x2_t *p) +{ + *p = (vint8m1x2_t) {}; +} + +/* { dg-final { scan-assembler-times {(?:vmv\.v\.i|vmv1r\.v)\s+v(?:8|9|10|11),} 4 } } */ +/* { dg-final { scan-assembler-times {vs1r\.v|vse8\.v} 2 } } */