summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-23 18:05:09 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-23 18:05:09 +0000
commit31139c311cb4b1cee0a53d6f3d5a79280991ce0d (patch)
treeeb784efb3d0e852cb6b6e8867f1546084f5fd39a
parentb410db752ea747664820787bdb2166f6a294a95d (diff)
downloadgcc-31139c311cb4b1cee0a53d6f3d5a79280991ce0d.tar.gz
* fold-const.c (operand_equal_p): Handle matching of vector
constructors. * gcc.dg/tree-ssa/operand-equal-2.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229264 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c50
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/operand-equal-2.c12
4 files changed, 71 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 21365db5f4f..df246e672ed 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-23 Jan Hubicka <hubicka@ucw.cz>
+
+ * fold-const.c (operand_equal_p): Handle matching of vector
+ constructors.
+
2015-10-23 David Edelsohn <dje.gcc@gmail.com>
* doc/install.texi (*-ibm-aix*): Additional information for AIX 7.1.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c1dcdd65836..018cb03f899 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -3149,6 +3149,56 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
&& DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1)
&& DECL_FUNCTION_CODE (arg0) == DECL_FUNCTION_CODE (arg1));
+ case tcc_exceptional:
+ if (TREE_CODE (arg0) == CONSTRUCTOR)
+ {
+ /* In GIMPLE constructors are used only to build vectors from
+ elements. Individual elements in the constructor must be
+ indexed in increasing order and form an initial sequence.
+
+ We make no effort to compare constructors in generic.
+ (see sem_variable::equals in ipa-icf which can do so for
+ constants). */
+ if (!VECTOR_TYPE_P (TREE_TYPE (arg0))
+ || !VECTOR_TYPE_P (TREE_TYPE (arg1)))
+ return 0;
+
+ /* Be sure that vectors constructed have the same representation.
+ We only tested element precision and modes to match.
+ Vectors may be BLKmode and thus also check that the number of
+ parts match. */
+ if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0))
+ != TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)))
+ return 0;
+
+ vec<constructor_elt, va_gc> *v0 = CONSTRUCTOR_ELTS (arg0);
+ vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (arg1);
+ unsigned int len = vec_safe_length (v0);
+
+ if (len != vec_safe_length (v1))
+ return 0;
+
+ for (unsigned int i = 0; i < len; i++)
+ {
+ constructor_elt *c0 = &(*v0)[i];
+ constructor_elt *c1 = &(*v1)[i];
+
+ if (!operand_equal_p (c0->value, c1->value, flags)
+ /* In GIMPLE the indexes can be either NULL or matching i.
+ Double check this so we won't get false
+ positives for GENERIC. */
+ || (c0->index
+ && (TREE_CODE (c0->index) != INTEGER_CST
+ || !compare_tree_int (c0->index, i)))
+ || (c1->index
+ && (TREE_CODE (c1->index) != INTEGER_CST
+ || !compare_tree_int (c1->index, i))))
+ return 0;
+ }
+ return 1;
+ }
+ return 0;
+
default:
return 0;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5502b1163cf..bedb76a782a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2015-10-23 Jan Hubicka <hubicka@ucw.cz>
+
+ * gcc.dg/tree-ssa/operand-equal-2.c: New testcase.
+
2015-10-23 Steve Ellcey <sellcey@imgtec.com>
Andrew Pinski <apinski@cavium.com>
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/operand-equal-2.c b/gcc/testsuite/gcc.dg/tree-ssa/operand-equal-2.c
new file mode 100644
index 00000000000..46fa323b4d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/operand-equal-2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop1" } */
+
+typedef char __attribute__ ((vector_size (4))) v4qi;
+
+v4qi v;
+void ret(char a)
+{
+ v4qi c={a,a,a,a},d={a,a,a,a};
+ v = (c!=d);
+}
+/* { dg-final { scan-tree-dump "v = . 0, 0, 0, 0 ." "forwprop2"} } */