* [PATCH] store-merging: Allow enums during bswap recognition [PR94403]
@ 2020-03-31 8:12 Jakub Jelinek
2020-03-31 8:53 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-03-31 8:12 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
The following testcase is optimized with char/unsigned char/signed char,
but not with std::byte. The following patch fixes that. Didn't use
INTEGRAL_TYPE_P because bswapping bools is just too weird.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for GCC11 (or is
it simple enough that we want it in GCC10 already)?
2020-03-31 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/94403
* gimple-ssa-store-merging.c (verify_symbolic_number_p): Allow also
ENUMERAL_TYPE lhs_type.
* g++.dg/tree-ssa/pr94403.C: New test.
--- gcc/gimple-ssa-store-merging.c.jj 2020-03-20 09:33:03.602112329 +0100
+++ gcc/gimple-ssa-store-merging.c 2020-03-30 18:30:31.723341519 +0200
@@ -315,7 +315,8 @@ verify_symbolic_number_p (struct symboli
lhs_type = gimple_expr_type (stmt);
- if (TREE_CODE (lhs_type) != INTEGER_TYPE)
+ if (TREE_CODE (lhs_type) != INTEGER_TYPE
+ && TREE_CODE (lhs_type) != ENUMERAL_TYPE)
return false;
if (TYPE_PRECISION (lhs_type) != TYPE_PRECISION (n->type))
--- gcc/testsuite/g++.dg/tree-ssa/pr94403.C.jj 2020-03-30 18:42:28.563719010 +0200
+++ gcc/testsuite/g++.dg/tree-ssa/pr94403.C 2020-03-30 18:51:21.135828389 +0200
@@ -0,0 +1,37 @@
+// PR tree-optimization/94403
+// Only test on some 64-bit targets which do have bswap{si,di}2 patterns and
+// are either big or little endian (not pdp endian).
+// { dg-do compile { target { lp64 && { i?86-*-* x86_64-*-* powerpc*-*-* aarch64*-*-* } } } }
+// { dg-require-effective-target store_merge }
+// { dg-options "-O2 -fdump-tree-store-merging -std=c++17" }
+
+namespace std {
+ template <typename T>
+ void swap (T& t1, T& t2) { T tmp (t1); t1 = t2; t2 = tmp; }
+ enum class byte : unsigned char {};
+}
+
+unsigned
+bswap32 (unsigned int x)
+{
+ unsigned int y = x;
+ std::byte *bytes = reinterpret_cast<std::byte*> (&y);
+ std::swap (bytes[0], bytes[3]);
+ std::swap (bytes[1], bytes[2]);
+ return y;
+}
+
+unsigned long long
+bswap64 (unsigned long long x)
+{
+ unsigned long long y = x;
+ std::byte *bytes = reinterpret_cast<std::byte*> (&y);
+ std::swap (bytes[0], bytes[7]);
+ std::swap (bytes[1], bytes[6]);
+ std::swap (bytes[2], bytes[5]);
+ std::swap (bytes[3], bytes[4]);
+ return y;
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin_bswap64" 1 "store-merging" } } */
+/* { dg-final { scan-tree-dump-times "__builtin_bswap32" 1 "store-merging" } } */
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] store-merging: Allow enums during bswap recognition [PR94403]
2020-03-31 8:12 [PATCH] store-merging: Allow enums during bswap recognition [PR94403] Jakub Jelinek
@ 2020-03-31 8:53 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2020-03-31 8:53 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Tue, 31 Mar 2020, Jakub Jelinek wrote:
> Hi!
>
> The following testcase is optimized with char/unsigned char/signed char,
> but not with std::byte. The following patch fixes that. Didn't use
> INTEGRAL_TYPE_P because bswapping bools is just too weird.
Is it?
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for GCC11 (or is
> it simple enough that we want it in GCC10 already)?
OK for GCC 10.
Richard.
> 2020-03-31 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/94403
> * gimple-ssa-store-merging.c (verify_symbolic_number_p): Allow also
> ENUMERAL_TYPE lhs_type.
>
> * g++.dg/tree-ssa/pr94403.C: New test.
>
> --- gcc/gimple-ssa-store-merging.c.jj 2020-03-20 09:33:03.602112329 +0100
> +++ gcc/gimple-ssa-store-merging.c 2020-03-30 18:30:31.723341519 +0200
> @@ -315,7 +315,8 @@ verify_symbolic_number_p (struct symboli
>
> lhs_type = gimple_expr_type (stmt);
>
> - if (TREE_CODE (lhs_type) != INTEGER_TYPE)
> + if (TREE_CODE (lhs_type) != INTEGER_TYPE
> + && TREE_CODE (lhs_type) != ENUMERAL_TYPE)
> return false;
>
> if (TYPE_PRECISION (lhs_type) != TYPE_PRECISION (n->type))
> --- gcc/testsuite/g++.dg/tree-ssa/pr94403.C.jj 2020-03-30 18:42:28.563719010 +0200
> +++ gcc/testsuite/g++.dg/tree-ssa/pr94403.C 2020-03-30 18:51:21.135828389 +0200
> @@ -0,0 +1,37 @@
> +// PR tree-optimization/94403
> +// Only test on some 64-bit targets which do have bswap{si,di}2 patterns and
> +// are either big or little endian (not pdp endian).
> +// { dg-do compile { target { lp64 && { i?86-*-* x86_64-*-* powerpc*-*-* aarch64*-*-* } } } }
> +// { dg-require-effective-target store_merge }
> +// { dg-options "-O2 -fdump-tree-store-merging -std=c++17" }
> +
> +namespace std {
> + template <typename T>
> + void swap (T& t1, T& t2) { T tmp (t1); t1 = t2; t2 = tmp; }
> + enum class byte : unsigned char {};
> +}
> +
> +unsigned
> +bswap32 (unsigned int x)
> +{
> + unsigned int y = x;
> + std::byte *bytes = reinterpret_cast<std::byte*> (&y);
> + std::swap (bytes[0], bytes[3]);
> + std::swap (bytes[1], bytes[2]);
> + return y;
> +}
> +
> +unsigned long long
> +bswap64 (unsigned long long x)
> +{
> + unsigned long long y = x;
> + std::byte *bytes = reinterpret_cast<std::byte*> (&y);
> + std::swap (bytes[0], bytes[7]);
> + std::swap (bytes[1], bytes[6]);
> + std::swap (bytes[2], bytes[5]);
> + std::swap (bytes[3], bytes[4]);
> + return y;
> +}
> +
> +/* { dg-final { scan-tree-dump-times "__builtin_bswap64" 1 "store-merging" } } */
> +/* { dg-final { scan-tree-dump-times "__builtin_bswap32" 1 "store-merging" } } */
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-31 8:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31 8:12 [PATCH] store-merging: Allow enums during bswap recognition [PR94403] Jakub Jelinek
2020-03-31 8:53 ` Richard Biener
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).