[PATCH] Fix PR tree-opt/38865 missing FRE with VIEW_CONVERT_EXPR
Andrew Pinski
pinskia@gmail.com
Wed Apr 22 21:11:00 GMT 2009
Hi,
The issue here is that we have:
sv_1(D)->i = { 0, 0, 0, 0 };
D.1242_2 = VIEW_CONVERT_EXPR<vector float>(sv_1(D)->i);
And FRE/PRE does not see that it could look through the VCE even
though we could.
This patch allows SCCVN to look through the VCE.
OK? Bootstrapped and tested on i686-linux-gnu with no regressions.
Thanks,
Andrew Pinski
ChangeLog:
* tree-ssa-sccvn.c (visit_reference_op_load): If vn_reference_lookup
is returns NULL and OP is a VCE, look through the VCE.
(visit_reference_op_store): Unwrap the VCE.
* gcc.dg/tree-ssa/fre-vce-1.c: New testcase.
-------------- next part --------------
Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c (revision 146612)
+++ tree-ssa-sccvn.c (working copy)
@@ -1700,6 +1700,12 @@
bool changed = false;
tree result = vn_reference_lookup (op, gimple_vuse (stmt), true, NULL);
+ /* If we have a VCE, try looking up its operand as it might be stored in
+ a different type. */
+ if (!result && TREE_CODE (op) == VIEW_CONVERT_EXPR)
+ result = vn_reference_lookup (TREE_OPERAND (op, 0), gimple_vuse (stmt),
+ true, NULL);
+
/* We handle type-punning through unions by value-numbering based
on offset and size of the access. Be prepared to handle a
type-mismatch here via creating a VIEW_CONVERT_EXPR. */
@@ -1793,6 +1799,10 @@
tree result;
bool resultsame = false;
+ /* If the lhs is a VCE, look past it. */
+ if (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
+ lhs = TREE_OPERAND (lhs, 0);
+
/* First we want to lookup using the *vuses* from the store and see
if there the last store to this location with the same address
had the same value.
Index: testsuite/gcc.dg/tree-ssa/fre-vce-1.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/fre-vce-1.c (revision 0)
+++ testsuite/gcc.dg/tree-ssa/fre-vce-1.c (revision 0)
@@ -0,0 +1,35 @@
+/* { dg-options "-O2 -fdump-tree-fre -w" } */
+/* { dg-do compile } */
+#define vector __attribute__((vector_size(sizeof(int)*4) ))
+struct s { vector int i; };
+vector float f(struct s *sv)
+{
+ sv->i = (vector int){0, 0, 0, 0};
+ return (vector float)sv->i;
+}
+
+
+vector float f1(struct s *sv, vector int a)
+{
+ sv->i = a;
+ return (vector float)sv->i;
+}
+
+struct s1 { int i; };
+
+void g(struct s1 *, float);
+void a1 (struct s1 sv)
+{
+ sv.i = 0;
+ g(&sv, *(float*)&sv.i);
+}
+
+
+void a2 (struct s1 sv, int i)
+{
+ sv.i = i;
+ g(&sv, *(float*)&sv.i);
+}
+
+/* { dg-final { scan-tree-dump-times 2 "fre" "sv_\[0-9\]\\\(D\\\)->i" } } */
+/* { dg-final { scan-tree-dump-times 2 "fre" "sv.i" } } */
More information about the Gcc-patches
mailing list