public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Iain Buclaw <ibuclaw@gdcproject.org>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [committed] d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
Date: Sun, 3 Mar 2024 11:41:03 +0100	[thread overview]
Message-ID: <C7E5047C-A132-4013-BEBD-E883BA4FAD0E@gmail.com> (raw)
In-Reply-To: <20240303014837.808610-1-ibuclaw@gdcproject.org>



> Am 03.03.2024 um 02:51 schrieb Iain Buclaw <ibuclaw@gdcproject.org>:
> 
> Hi,
> 
> This patch fixes a wrong code issue in the D front-end where lowered
> struct comparisons would reinterpret fields with a different (usually
> bigger) alignment than the original.  Use `build_aligned_type' to
> preserve the alignment when casting away for such comparisons.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
> to mainline, and backported to releases/gcc-13, releases/gcc-12, and
> releases/gcc-11.

LGTM.  You might want to experiment with not doing the premature optimization but instead use __builtin_memcmp_eq (assuming that’s a general good fit).  The middle-end should better turn that into target optimal code.

Richard 

> Regards,
> Iain.
> ---
>    PR d/114171
> 
> gcc/d/ChangeLog:
> 
>    * d-codegen.cc (lower_struct_comparison): Keep alignment of original
>    type in reinterpret cast for comparison.
> 
> gcc/testsuite/ChangeLog:
> 
>    * gdc.dg/torture/pr114171.d: New test.
> ---
> gcc/d/d-codegen.cc                      |  1 +
> gcc/testsuite/gdc.dg/torture/pr114171.d | 29 +++++++++++++++++++++++++
> 2 files changed, 30 insertions(+)
> create mode 100644 gcc/testsuite/gdc.dg/torture/pr114171.d
> 
> diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
> index 5bc233928aa..43d7739f8fc 100644
> --- a/gcc/d/d-codegen.cc
> +++ b/gcc/d/d-codegen.cc
> @@ -1006,6 +1006,7 @@ lower_struct_comparison (tree_code code, StructDeclaration *sd,
>          if (tmode == NULL_TREE)
>        tmode = make_unsigned_type (GET_MODE_BITSIZE (mode.require ()));
> 
> +          tmode = build_aligned_type (tmode, TYPE_ALIGN (stype));
>          t1ref = build_vconvert (tmode, t1ref);
>          t2ref = build_vconvert (tmode, t2ref);
> 
> diff --git a/gcc/testsuite/gdc.dg/torture/pr114171.d b/gcc/testsuite/gdc.dg/torture/pr114171.d
> new file mode 100644
> index 00000000000..0f9ffcab916
> --- /dev/null
> +++ b/gcc/testsuite/gdc.dg/torture/pr114171.d
> @@ -0,0 +1,29 @@
> +// { dg-do run }
> +// { dg-additional-options "-mavx" { target avx_runtime } }
> +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
> +import gcc.builtins;
> +
> +struct S1
> +{
> +    string label;
> +}
> +
> +struct S2
> +{
> +    ulong pad;
> +    S1 label;
> +}
> +
> +pragma(inline, false)
> +auto newitem()
> +{
> +    void *p = __builtin_malloc(S2.sizeof);
> +    __builtin_memset(p, 0, S2.sizeof);
> +    return cast(S2*) p;
> +}
> +
> +int main()
> +{
> +    auto bn = newitem();
> +    return bn.label is S1.init ? 0 : 1;
> +}
> --
> 2.40.1
> 

  reply	other threads:[~2024-03-03 10:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03  1:48 Iain Buclaw
2024-03-03 10:41 ` Richard Biener [this message]
2024-03-03 14:23   ` Iain Buclaw
2024-03-03 22:49 ` Andrew Pinski
2024-03-03 23:09   ` Iain Buclaw

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=C7E5047C-A132-4013-BEBD-E883BA4FAD0E@gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ibuclaw@gdcproject.org \
    /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).