public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [libstdc++] [testsuite] disable SRA for compare_exchange_padding
@ 2024-04-16  3:49 Alexandre Oliva
  2024-04-16  6:44 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2024-04-16  3:49 UTC (permalink / raw)
  To: gcc-patches, libstdc++


On arm-vx7r2, the uses of as.load() as initializer get SRAed, so the
padding bits in the tests are not what we might expect from full-word
struct copies.

I tried adding a function to perform bitwise copying, but even taking
the as.load() argument by const&, we'd still construct a temporary
with SRAed field-wise copying.  Unable to find another way to ensure
we wouldn't get a temporary, I went for disabling SRA.

Regstrapped on x86_64-linux-gnu.  Also tested with gcc-13 on arm-,
aarch64-, x86- and x86_64-vxworks7r2.  Ok to install?


for  libstdc++-v3/ChangeLog

	* testsuite/29_atomics/atomic/compare_exchange_padding.cc:
        Disable SRA.
---
 .../29_atomics/atomic/compare_exchange_padding.cc  |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
index 2f18d426e7f7e..a6081968ca869 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
@@ -1,6 +1,7 @@
 // { dg-do run { target c++20 } }
 // { dg-require-atomic-cmpxchg-word "" }
 // { dg-add-options libatomic }
+// { dg-additional-options "-fno-tree-sra" }
 
 #include <atomic>
 #include <cstring>
@@ -26,10 +27,10 @@ main ()
   s.s = 42;
 
   std::atomic<S> as{ s };
-  auto ts = as.load();
+  auto ts = as.load(); // SRA might prevent copying of padding bits here.
   VERIFY( !compare_struct(s, ts) ); // padding cleared on construction
   as.exchange(s);
-  auto es = as.load();
+  auto es = as.load(); // SRA might prevent copying of padding bits here.
   VERIFY( compare_struct(ts, es) ); // padding cleared on exchange
 
   S n;

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [libstdc++] [testsuite] disable SRA for compare_exchange_padding
  2024-04-16  3:49 [PATCH] [libstdc++] [testsuite] disable SRA for compare_exchange_padding Alexandre Oliva
@ 2024-04-16  6:44 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2024-04-16  6:44 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, libstdc++

On Tue, 16 Apr 2024 at 04:49, Alexandre Oliva <oliva@adacore.com> wrote:
>
>
> On arm-vx7r2, the uses of as.load() as initializer get SRAed, so the
> padding bits in the tests are not what we might expect from full-word
> struct copies.

Aha, I was wondering why this was failing on ARM!


> I tried adding a function to perform bitwise copying, but even taking
> the as.load() argument by const&, we'd still construct a temporary
> with SRAed field-wise copying.  Unable to find another way to ensure
> we wouldn't get a temporary, I went for disabling SRA.
>
> Regstrapped on x86_64-linux-gnu.  Also tested with gcc-13 on arm-,
> aarch64-, x86- and x86_64-vxworks7r2.  Ok to install?

Yes, thanks.

>
>
> for  libstdc++-v3/ChangeLog
>
>         * testsuite/29_atomics/atomic/compare_exchange_padding.cc:
>         Disable SRA.
> ---
>  .../29_atomics/atomic/compare_exchange_padding.cc  |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
> index 2f18d426e7f7e..a6081968ca869 100644
> --- a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
> +++ b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
> @@ -1,6 +1,7 @@
>  // { dg-do run { target c++20 } }
>  // { dg-require-atomic-cmpxchg-word "" }
>  // { dg-add-options libatomic }
> +// { dg-additional-options "-fno-tree-sra" }
>
>  #include <atomic>
>  #include <cstring>
> @@ -26,10 +27,10 @@ main ()
>    s.s = 42;
>
>    std::atomic<S> as{ s };
> -  auto ts = as.load();
> +  auto ts = as.load(); // SRA might prevent copying of padding bits here.
>    VERIFY( !compare_struct(s, ts) ); // padding cleared on construction
>    as.exchange(s);
> -  auto es = as.load();
> +  auto es = as.load(); // SRA might prevent copying of padding bits here.
>    VERIFY( compare_struct(ts, es) ); // padding cleared on exchange
>
>    S n;
>
> --
> Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
>    Free Software Activist                   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-16  6:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16  3:49 [PATCH] [libstdc++] [testsuite] disable SRA for compare_exchange_padding Alexandre Oliva
2024-04-16  6:44 ` Jonathan Wakely

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).