From: Richard Sandiford <richard.sandiford@arm.com>
To: "Andre Vieira \(lists\)" <andre.simoesdiasvieira@arm.com>
Cc: Richard Biener <richard.guenther@gmail.com>,
"gcc-patches\@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [AArch64] Fix TBAA information when lowering NEON loads and stores to gimple
Date: Tue, 09 Nov 2021 15:00:33 +0000 [thread overview]
Message-ID: <mpto86twezy.fsf@arm.com> (raw)
In-Reply-To: <8c2845ce-b5df-fd4b-18b0-ef870be6761a@arm.com> (Andre Vieira's message of "Tue, 9 Nov 2021 12:27:19 +0000")
"Andre Vieira (lists)" <andre.simoesdiasvieira@arm.com> writes:
> And second (also added a test):
>
> [AArch64] Fix TBAA information when lowering NEON loads and stores to gimple
>
> This patch fixes the wrong TBAA information when lowering NEON loads and
> stores
> to gimple that showed up when bootstrapping with UBSAN.
>
> gcc/ChangeLog:
>
> * config/aarch64/aarch64-builtins.c
> (aarch64_general_gimple_fold_builtin): Change pointer alignment and alias.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/aarch64/simd/lowering_tbaa.c: New test.
OK, thanks.
Richard
> diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
> index a815e4cfbccab692ca688ba87c71b06c304abbfb..e06131a7c61d31c1be3278dcdccc49c3053c78cb 100644
> --- a/gcc/config/aarch64/aarch64-builtins.c
> +++ b/gcc/config/aarch64/aarch64-builtins.c
> @@ -2485,18 +2485,18 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt,
> = get_mem_type_for_load_store(fcode);
> aarch64_simd_type_info simd_type
> = aarch64_simd_types[mem_type];
> - tree elt_ptr_type = build_pointer_type (simd_type.eltype);
> + tree elt_ptr_type = build_pointer_type_for_mode (simd_type.eltype,
> + VOIDmode, true);
> tree zero = build_zero_cst (elt_ptr_type);
> - gimple_seq stmts = NULL;
> - tree base = gimple_convert (&stmts, elt_ptr_type,
> - args[0]);
> - if (stmts)
> - gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
> + /* Use element type alignment. */
> + tree access_type
> + = build_aligned_type (simd_type.itype,
> + TYPE_ALIGN (simd_type.eltype));
> new_stmt
> = gimple_build_assign (gimple_get_lhs (stmt),
> fold_build2 (MEM_REF,
> - simd_type.itype,
> - base, zero));
> + access_type,
> + args[0], zero));
> }
> break;
>
> @@ -2507,18 +2507,17 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt,
> = get_mem_type_for_load_store(fcode);
> aarch64_simd_type_info simd_type
> = aarch64_simd_types[mem_type];
> - tree elt_ptr_type = build_pointer_type (simd_type.eltype);
> + tree elt_ptr_type = build_pointer_type_for_mode (simd_type.eltype,
> + VOIDmode, true);
> tree zero = build_zero_cst (elt_ptr_type);
> - gimple_seq stmts = NULL;
> - tree base = gimple_convert (&stmts, elt_ptr_type,
> - args[0]);
> - if (stmts)
> - gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
> + /* Use element type alignment. */
> + tree access_type
> + = build_aligned_type (simd_type.itype,
> + TYPE_ALIGN (simd_type.eltype));
> new_stmt
> - = gimple_build_assign (fold_build2 (MEM_REF,
> - simd_type.itype,
> - base,
> - zero), args[1]);
> + = gimple_build_assign (fold_build2 (MEM_REF, access_type,
> + args[0], zero),
> + args[1]);
> }
> break;
>
> diff --git a/gcc/testsuite/gcc.target/aarch64/simd/lowering_tbaa.c b/gcc/testsuite/gcc.target/aarch64/simd/lowering_tbaa.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..eaeae21f19c7d2d8d4e032f2f8b1b22bb96b7ca4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/simd/lowering_tbaa.c
> @@ -0,0 +1,30 @@
> +/* Tests the TBAA information of lowered AArch64 SIMD loads. */
> +/* { dg-do run } */
> +/* { dg-options "-save-temps -O2" } */
> +
> +#include <arm_neon.h>
> +
> +void __attribute__((noipa))
> +g (float *)
> +{
> +}
> +
> +int32x4_t __attribute__((noipa))
> +f (void)
> +{
> + float a[4] = { 1, 2, 3, 4 };
> + g (a);
> + a[0] = a[1] = a[2] = a[3] = 0;
> + void *volatile ptr = a;
> + return vld1q_s32 ((int32_t *) ptr);
> +}
> +
> +int
> +main (void)
> +{
> + int32x4_t x = f ();
> + int32x4_t y = vdupq_n_s32 (0);
> + if (__builtin_memcmp (&x, &y, 16) != 0)
> + __builtin_abort ();
> + return 0;
> +}
prev parent reply other threads:[~2021-11-09 15:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 9:55 [AArch64] Fix NEON load/store gimple lowering and big-endian testisms Andre Vieira (lists)
2021-11-04 17:48 ` Richard Sandiford
2021-11-05 10:27 ` Richard Biener
2021-11-09 9:19 ` Andre Vieira (lists)
2021-11-09 10:47 ` Richard Biener
2021-11-09 12:24 ` [AArch64] Fix big-endian testisms introduced by NEON gimple lowering patch Andre Vieira (lists)
2021-11-09 12:27 ` [AArch64] Fix TBAA information when lowering NEON loads and stores to gimple Andre Vieira (lists)
2021-11-09 15:00 ` Richard Sandiford [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mpto86twezy.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=andre.simoesdiasvieira@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).