Patchwork Fix PR53663

login
register
mail settings
Submitter Richard Guenther
Date Sept. 24, 2012, 2:23 p.m.
Message ID <alpine.LNX.2.00.1209241621430.4063@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/186428/
State New
Headers show

Comments

Richard Guenther - Sept. 24, 2012, 2:23 p.m.
This fixes PR53663 - for redundant store removal we may not
use VN translation, but the native encode / interpret trick
is of such a kind because it looks through type changes.
Thus, mark it so.

Bootstrap and regtest queued on x86_64-unknown-linux-gnu.

Richard.

2012-09-24  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/53663
	* tree-ssa-sccvn.c (vn_reference_lookup_3): Conditional
	native encode/interpret translation on VN_WALKREWRITE.

	* gcc.dg/torture/pr53663-1.c: New testcase.
	* gcc.dg/torture/pr53663-2.c: Likewise.
	* gcc.dg/torture/pr53663-3.c: Likewise.

Patch

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c	(revision 191664)
+++ gcc/tree-ssa-sccvn.c	(working copy)
@@ -1555,7 +1555,8 @@  vn_reference_lookup_3 (ao_ref *ref, tree
 
   /* 3) Assignment from a constant.  We can use folds native encode/interpret
      routines to extract the assigned bits.  */
-  else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
+  else if (vn_walk_kind == VN_WALKREWRITE
+	   && CHAR_BIT == 8 && BITS_PER_UNIT == 8
 	   && ref->size == maxsize
 	   && maxsize % BITS_PER_UNIT == 0
 	   && offset % BITS_PER_UNIT == 0
Index: gcc/testsuite/gcc.dg/torture/pr53663-3.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr53663-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr53663-3.c	(working copy)
@@ -0,0 +1,24 @@ 
+/* { dg-do run } */
+
+extern void abort (void);
+
+union u
+{
+  int i;
+  float f;
+} v;
+
+float foo (float *f)
+{
+  *f = 1;
+  v.i = 0;
+  v.f = 0.;
+  return *f;
+}
+
+int main()
+{
+  if (foo (&v.f) != 0.)
+    abort ();
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/torture/pr53663-2.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr53663-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr53663-2.c	(working copy)
@@ -0,0 +1,24 @@ 
+/* { dg-do run } */
+
+extern void abort (void);
+
+union u
+{
+  int i;
+  short f;
+} v;
+
+short foo (short *f)
+{
+  *f = 1;
+  v.i = 0;
+  v.f = 0;
+  return *f;
+}
+
+int main()
+{
+  if (foo (&v.f) != 0)
+    abort ();
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/torture/pr53663-1.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr53663-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr53663-1.c	(working copy)
@@ -0,0 +1,30 @@ 
+/* { dg-do run } */
+
+extern void abort (void);
+
+union u
+{
+  int i;
+  _Bool b;
+};
+
+void f(union u * vp, union u v)
+{
+  *vp = v;
+}
+
+int main()
+{
+  union u v;
+  union u v1;
+  union u v2;
+
+  v.i = 10;
+  f(&v1, v);
+
+  v.b = 0;
+  f(&v2, v);
+  if (v2.b != 0)
+    abort ();
+  return 0;
+}