The following reverts back to the old unroll heuristics before my
PR91975 changes but implements "consistency" the other way around.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2019-11-15  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/92039
        PR tree-optimization/91975
        * tree-ssa-loop-ivcanon.c (constant_after_peeling): Revert
        previous change, treat invariants consistently as non-constant.
        (tree_estimate_loop_size): Ternary ops with just the first op
        constant are not optimized away.

        * gcc.dg/tree-ssa/cunroll-2.c: Revert to state previous to
        unroller adjustment.
        * g++.dg/tree-ssa/ivopts-3.C: Likewise.

Index: gcc/tree-ssa-loop-ivcanon.c
===================================================================
--- gcc/tree-ssa-loop-ivcanon.c (revision 278276)
+++ gcc/tree-ssa-loop-ivcanon.c (working copy)
@@ -163,7 +163,7 @@ struct loop_size
 static bool
 constant_after_peeling (tree op, gimple *stmt, class loop *loop)
 {
-  if (is_gimple_min_invariant (op))
+  if (CONSTANT_CLASS_P (op))
     return true;
 
   /* We can still fold accesses to constant arrays when index is known.  */
@@ -195,8 +195,9 @@ constant_after_peeling (tree op, gimple
   /* Induction variables are constants when defined in loop.  */
   if (loop_containing_stmt (stmt) != loop)
     return false;
-  tree ev = instantiate_parameters (loop, analyze_scalar_evolution (loop, op));
-  if (chrec_contains_undetermined (ev))
+  tree ev = analyze_scalar_evolution (loop, op);
+  if (chrec_contains_undetermined (ev)
+      || chrec_contains_symbols (ev))
     return false;
   return true;
 }
@@ -293,7 +294,8 @@ tree_estimate_loop_size (class loop *loo
                                                  stmt, loop)
                       && (gimple_assign_rhs_class (stmt) != GIMPLE_BINARY_RHS
                           || constant_after_peeling (gimple_assign_rhs2 (stmt),
-                                                     stmt, loop)))
+                                                     stmt, loop))
+                      && gimple_assign_rhs_class (stmt) != GIMPLE_TERNARY_RHS)
                {
                  size->constant_iv = true;
                  if (dump_file && (dump_flags & TDF_DETAILS))
Index: gcc/testsuite/gcc.dg/tree-ssa/cunroll-2.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/cunroll-2.c   (revision 278276)
+++ gcc/testsuite/gcc.dg/tree-ssa/cunroll-2.c   (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -fdump-tree-cunrolli-details" } */
+/* { dg-options "-O3 -fdump-tree-cunroll-details" } */
 int a[2];
 int test2 (void);
 void
@@ -14,4 +14,4 @@ test(int c)
     }
 }
 /* We are not able to get rid of the final conditional because the loop has 
two exits.  */
-/* { dg-final { scan-tree-dump "loop with 2 iterations completely unrolled" 
"cunrolli"} } */
+/* { dg-final { scan-tree-dump "loop with 1 iterations completely unrolled" 
"cunroll"} } */
Index: gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C
===================================================================
--- gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C    (revision 278276)
+++ gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C    (working copy)
@@ -70,8 +70,6 @@ int main ( int , char** ) {
     return 0;
 }
 
-// Verify that on x86_64 and i?86 we unroll the innsermost loop and
-// use three IVs for the then innermost loop
+// Verify that on x86_64 and i?86 we use a single IV for the innermost loop
 
-// { dg-final { scan-tree-dump "Selected IV set for loop \[0-9\]* at \[^ 
\]*:63, 127 avg niters, 3 IVs" "ivopts" { target x86_64-*-* i?86-*-* } } }
-// { dg-final { scan-tree-dump-not "Selected IV set for loop \[0-9\]* at \[^ 
\]*:64" "ivopts" { target x86_64-*-* i?86-*-* } } }
+// { dg-final { scan-tree-dump "Selected IV set for loop \[0-9\]* at \[^ 
\]*:64, 3 avg niters, 1 IVs" "ivopts" { target x86_64-*-* i?86-*-* } } }

Reply via email to