[Bug tree-optimization/82397] [8 Regression] qsort comparator non-negative on sorted output: 1 in vect_analyze_data_ref_accesses

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Oct 5 13:51:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82397

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ok, so I'm going to remove all the operand_equal_p tests as a first step.  As a
second we can add cleverness like the following (but we really would like to
do this "flatter" in the end...).  iterative_hash_expr could compute it once
for each node in the tree and we could pass the info down when recursing.
Need to think about some clever way to do that tho...

Index: tree-data-ref.c
===================================================================
--- tree-data-ref.c     (revision 253437)
+++ tree-data-ref.c     (working copy)
@@ -1251,6 +1251,28 @@ data_ref_compare_tree (tree t1, tree t2)
          break;
        }

+      if (commutative_tree_code (code))
+       {
+         tree t10 = TREE_OPERAND (t1, 0);
+         tree t11 = TREE_OPERAND (t1, 1);
+         tree t20 = TREE_OPERAND (t2, 0);
+         tree t21 = TREE_OPERAND (t2, 1);
+         /* Apply "clever" canonicalization to detect more equalities.
+            ???  Doing this here rather than in whoever builds the
+            trees makes it exponential in the tree size.  */
+         if (iterative_hash_expr (t10, 0) > iterative_hash_expr (t11, 0))
+           std::swap (t10, t11);
+         if (iterative_hash_expr (t20, 0) > iterative_hash_expr (t21, 0))
+           std::swap (t20, t21);
+         cmp = data_ref_compare_tree (t10, t20);
+         if (cmp != 0)
+           return cmp;
+         cmp = data_ref_compare_tree (t11, t21);
+         if (cmp != 0)
+           return cmp;
+         return 0;
+       }
+
       /* For expressions with operands, compare their operands recursively. 
*/
       for (i = TREE_OPERAND_LENGTH (t1) - 1; i >= 0; --i)
        {


More information about the Gcc-bugs mailing list