public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/106513 - fix mistake in bswap symbolic number shifts
@ 2022-08-10 13:47 Richard Biener
  2022-08-10 13:59 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2022-08-10 13:47 UTC (permalink / raw)
  To: gcc-patches

This fixes a mistake in typing a local variable in the symbolic
shift routine.

Bootstrap & regtest pending on x86_64-unknown-linux-gnu.

	PR tree-optimization/106513
	* gimple-ssa-store-merging.cc (do_shift_rotate): Use uint64_t
	for head_marker.

	* gcc.dg/torture/pr106513.c: New testcase.
---
 gcc/gimple-ssa-store-merging.cc         |  2 +-
 gcc/testsuite/gcc.dg/torture/pr106513.c | 26 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106513.c

diff --git a/gcc/gimple-ssa-store-merging.cc b/gcc/gimple-ssa-store-merging.cc
index 0640168bcc4..b80b8eac444 100644
--- a/gcc/gimple-ssa-store-merging.cc
+++ b/gcc/gimple-ssa-store-merging.cc
@@ -263,7 +263,7 @@ do_shift_rotate (enum tree_code code,
 		 int count)
 {
   int i, size = TYPE_PRECISION (n->type) / BITS_PER_UNIT;
-  unsigned head_marker;
+  uint64_t head_marker;
 
   if (count < 0
       || count >= TYPE_PRECISION (n->type)
diff --git a/gcc/testsuite/gcc.dg/torture/pr106513.c b/gcc/testsuite/gcc.dg/torture/pr106513.c
new file mode 100644
index 00000000000..92c02ffb37b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106513.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+
+typedef __INT64_TYPE__ int64_t;
+
+__attribute__((noinline)) int64_t
+swap64 (int64_t n)
+{
+  return (((n & (((int64_t) 0xff) )) << 56) |
+          ((n & (((int64_t) 0xff) << 8)) << 40) |
+          ((n & (((int64_t) 0xff) << 16)) << 24) |
+          ((n & (((int64_t) 0xff) << 24)) << 8) |
+          ((n & (((int64_t) 0xff) << 32)) >> 8) |
+          ((n & (((int64_t) 0xff) << 40)) >> 24) |
+          ((n & (((int64_t) 0xff) << 48)) >> 40) |
+          ((n & ((int64_t)(0xffull << 56))) >> 56));
+}
+
+int main (void)
+{
+  volatile int64_t n = 0x8000000000000000l;
+
+  if (swap64(n) != 0xffffffffffffff80l)
+    __builtin_abort ();
+
+  return 0;
+}
-- 
2.35.3

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

* Re: [PATCH] tree-optimization/106513 - fix mistake in bswap symbolic number shifts
  2022-08-10 13:47 [PATCH] tree-optimization/106513 - fix mistake in bswap symbolic number shifts Richard Biener
@ 2022-08-10 13:59 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-08-10 13:59 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Wed, Aug 10, 2022 at 03:47:10PM +0200, Richard Biener via Gcc-patches wrote:
> This fixes a mistake in typing a local variable in the symbolic
> shift routine.
> 
> Bootstrap & regtest pending on x86_64-unknown-linux-gnu.
> 
> 	PR tree-optimization/106513
> 	* gimple-ssa-store-merging.cc (do_shift_rotate): Use uint64_t
> 	for head_marker.

Ok.

> 
> 	* gcc.dg/torture/pr106513.c: New testcase.

> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr106513.c
> @@ -0,0 +1,26 @@
> +/* { dg-do run } */
> +
> +typedef __INT64_TYPE__ int64_t;
> +
> +__attribute__((noinline)) int64_t
> +swap64 (int64_t n)
> +{
> +  return (((n & (((int64_t) 0xff) )) << 56) |
> +          ((n & (((int64_t) 0xff) << 8)) << 40) |
> +          ((n & (((int64_t) 0xff) << 16)) << 24) |
> +          ((n & (((int64_t) 0xff) << 24)) << 8) |
> +          ((n & (((int64_t) 0xff) << 32)) >> 8) |
> +          ((n & (((int64_t) 0xff) << 40)) >> 24) |
> +          ((n & (((int64_t) 0xff) << 48)) >> 40) |
> +          ((n & ((int64_t)(0xffull << 56))) >> 56));
> +}
> +
> +int main (void)
> +{
> +  volatile int64_t n = 0x8000000000000000l;
> +
> +  if (swap64(n) != 0xffffffffffffff80l)
> +    __builtin_abort ();

Please use ll instead of l in both cases above.
Perhaps -0x80ll would be simpler...

	Jakub


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

end of thread, other threads:[~2022-08-10 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10 13:47 [PATCH] tree-optimization/106513 - fix mistake in bswap symbolic number shifts Richard Biener
2022-08-10 13:59 ` Jakub Jelinek

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