This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR53663
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 24 Sep 2012 16:23:08 +0200 (CEST)
- Subject: [PATCH] Fix PR53663
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.
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;
+}