bswap: Fix up bswap_view_convert after the recent change [PR99882]

Message ID 20210403075718.GI1179226@tucnak
State New
Headers show
Series
  • bswap: Fix up bswap_view_convert after the recent change [PR99882]
Related show

Commit Message

apinski--- via Gcc-patches April 3, 2021, 7:57 a.m.
Hi!

Martin reported that my recent change to allow pointer types in bswap
broke valgrind.  The bswap_view_convert function used for the initialization
of vector CONSTRUCTOR from the identity or byte-swapped pieces unfortunately
didn't handle pointer types.  The following patch handles it there.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-04-03  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/99882
	* gimple-ssa-store-merging.c (bswap_view_convert): Handle val with
	pointer type.

	* gcc.dg/pr99882.c: New test.


	Jakub

Comments

Richard Biener April 3, 2021, 8:02 a.m. | #1
On April 3, 2021 9:57:18 AM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!

>

>Martin reported that my recent change to allow pointer types in bswap

>broke valgrind.  The bswap_view_convert function used for the

>initialization

>of vector CONSTRUCTOR from the identity or byte-swapped pieces

>unfortunately

>didn't handle pointer types.  The following patch handles it there.

>

>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


Ok. 

Thanks, 
Richard. 

>2021-04-03  Jakub Jelinek  <jakub@redhat.com>

>

>	PR tree-optimization/99882

>	* gimple-ssa-store-merging.c (bswap_view_convert): Handle val with

>	pointer type.

>

>	* gcc.dg/pr99882.c: New test.

>

>--- gcc/gimple-ssa-store-merging.c.jj	2021-04-01 10:50:56.238629197

>+0200

>+++ gcc/gimple-ssa-store-merging.c	2021-04-02 16:52:38.763803716 +0200

>@@ -985,10 +985,19 @@ public:

> static tree

> bswap_view_convert (gimple_stmt_iterator *gsi, tree type, tree val)

> {

>-  gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (val)));

>+  gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (val))

>+	      || POINTER_TYPE_P (TREE_TYPE (val)));

>   if (TYPE_SIZE (type) != TYPE_SIZE (TREE_TYPE (val)))

>     {

>       HOST_WIDE_INT prec = TREE_INT_CST_LOW (TYPE_SIZE (type));

>+      if (POINTER_TYPE_P (TREE_TYPE (val)))

>+	{

>+	  gimple *g

>+	    = gimple_build_assign (make_ssa_name (pointer_sized_int_node),

>+				   NOP_EXPR, val);

>+	  gsi_insert_before (gsi, g, GSI_SAME_STMT);

>+	  val = gimple_assign_lhs (g);

>+	}

>       tree itype = build_nonstandard_integer_type (prec, 1);

>gimple *g = gimple_build_assign (make_ssa_name (itype), NOP_EXPR, val);

>       gsi_insert_before (gsi, g, GSI_SAME_STMT);

>--- gcc/testsuite/gcc.dg/pr99882.c.jj	2021-04-02 20:52:09.895060892

>+0200

>+++ gcc/testsuite/gcc.dg/pr99882.c	2021-04-02 20:51:39.590396850 +0200

>@@ -0,0 +1,37 @@

>+/* PR tree-optimization/99882 */

>+/* { dg-do compile } */

>+/* { dg-options "-O3" } */

>+

>+void

>+foo (char *p, void *q)

>+{

>+  __INTPTR_TYPE__ i = (__INTPTR_TYPE__) q;

>+  p[2] = i;

>+  i >>= 8;

>+  p[3] = i;

>+  i >>= 8;

>+  p[4] = i;

>+  i >>= 8;

>+  p[5] = i;

>+  i >>= 8;

>+  p[6] = i;

>+  i >>= 8;

>+  p[7] = i;

>+  i >>= 8;

>+  p[8] = i;

>+  i >>= 8;

>+  p[9] = i;

>+}

>+

>+void

>+bar (char *p, void *q)

>+{

>+  __INTPTR_TYPE__ i = (__INTPTR_TYPE__) q;

>+  p[2] = i;

>+  i >>= 8;

>+  p[3] = i;

>+  i >>= 8;

>+  p[4] = i;

>+  i >>= 8;

>+  p[5] = i;

>+}

>

>	Jakub

Patch

--- gcc/gimple-ssa-store-merging.c.jj	2021-04-01 10:50:56.238629197 +0200
+++ gcc/gimple-ssa-store-merging.c	2021-04-02 16:52:38.763803716 +0200
@@ -985,10 +985,19 @@  public:
 static tree
 bswap_view_convert (gimple_stmt_iterator *gsi, tree type, tree val)
 {
-  gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (val)));
+  gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (val))
+	      || POINTER_TYPE_P (TREE_TYPE (val)));
   if (TYPE_SIZE (type) != TYPE_SIZE (TREE_TYPE (val)))
     {
       HOST_WIDE_INT prec = TREE_INT_CST_LOW (TYPE_SIZE (type));
+      if (POINTER_TYPE_P (TREE_TYPE (val)))
+	{
+	  gimple *g
+	    = gimple_build_assign (make_ssa_name (pointer_sized_int_node),
+				   NOP_EXPR, val);
+	  gsi_insert_before (gsi, g, GSI_SAME_STMT);
+	  val = gimple_assign_lhs (g);
+	}
       tree itype = build_nonstandard_integer_type (prec, 1);
       gimple *g = gimple_build_assign (make_ssa_name (itype), NOP_EXPR, val);
       gsi_insert_before (gsi, g, GSI_SAME_STMT);
--- gcc/testsuite/gcc.dg/pr99882.c.jj	2021-04-02 20:52:09.895060892 +0200
+++ gcc/testsuite/gcc.dg/pr99882.c	2021-04-02 20:51:39.590396850 +0200
@@ -0,0 +1,37 @@ 
+/* PR tree-optimization/99882 */
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+void
+foo (char *p, void *q)
+{
+  __INTPTR_TYPE__ i = (__INTPTR_TYPE__) q;
+  p[2] = i;
+  i >>= 8;
+  p[3] = i;
+  i >>= 8;
+  p[4] = i;
+  i >>= 8;
+  p[5] = i;
+  i >>= 8;
+  p[6] = i;
+  i >>= 8;
+  p[7] = i;
+  i >>= 8;
+  p[8] = i;
+  i >>= 8;
+  p[9] = i;
+}
+
+void
+bar (char *p, void *q)
+{
+  __INTPTR_TYPE__ i = (__INTPTR_TYPE__) q;
+  p[2] = i;
+  i >>= 8;
+  p[3] = i;
+  i >>= 8;
+  p[4] = i;
+  i >>= 8;
+  p[5] = i;
+}