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

Richard.

2016-01-14  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/68060
        * tree-vect-loop.c (vect_is_simple_reduction): Check the
        outer loop reduction is only used in the inner loop before
        detecting a double reduction.

        * gcc.dg/torture/pr68060-1.c: New testcase.
        * gcc.dg/torture/pr68060-2.c: Likewise.

Index: gcc/tree-vect-loop.c
===================================================================
*** gcc/tree-vect-loop.c        (revision 232315)
--- gcc/tree-vect-loop.c        (working copy)
*************** vect_is_simple_reduction (loop_vec_info
*** 2591,2597 ****
    struct loop *vect_loop = LOOP_VINFO_LOOP (loop_info);
    edge latch_e = loop_latch_edge (loop);
    tree loop_arg = PHI_ARG_DEF_FROM_EDGE (phi, latch_e);
!   gimple *def_stmt, *def1 = NULL, *def2 = NULL;
    enum tree_code orig_code, code;
    tree op1, op2, op3 = NULL_TREE, op4 = NULL_TREE;
    tree type;
--- 2591,2597 ----
    struct loop *vect_loop = LOOP_VINFO_LOOP (loop_info);
    edge latch_e = loop_latch_edge (loop);
    tree loop_arg = PHI_ARG_DEF_FROM_EDGE (phi, latch_e);
!   gimple *def_stmt, *def1 = NULL, *def2 = NULL, *phi_use_stmt;
    enum tree_code orig_code, code;
    tree op1, op2, op3 = NULL_TREE, op4 = NULL_TREE;
    tree type;
*************** vect_is_simple_reduction (loop_vec_info
*** 2640,2645 ****
--- 2640,2647 ----
                             "reduction used in loop.\n");
            return NULL;
          }
+ 
+       phi_use_stmt = use_stmt;
      }
  
    if (TREE_CODE (loop_arg) != SSA_NAME)
*************** vect_is_simple_reduction (loop_vec_info
*** 2722,2728 ****
          && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt))
            && loop->inner
            && flow_bb_inside_loop_p (loop->inner, gimple_bb (def1))
!           && is_gimple_assign (def1))
          {
            if (dump_enabled_p ())
              report_vect_op (MSG_NOTE, def_stmt,
--- 2724,2731 ----
          && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt))
            && loop->inner
            && flow_bb_inside_loop_p (loop->inner, gimple_bb (def1))
!           && is_gimple_assign (def1)
!         && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt)))
          {
            if (dump_enabled_p ())
              report_vect_op (MSG_NOTE, def_stmt,
Index: gcc/testsuite/gcc.dg/torture/pr68060-1.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr68060-1.c    (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr68060-1.c    (working copy)
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do compile } */
+ 
+ int a, b, c;
+ 
+ int
+ main ()
+ {
+   for (; c; c++)
+     for (a = 0; a < 4; a++)
+       {
+       c &= 5;
+       for (b = 0; b < 2; b++)
+         c |= 1;
+       }
+   return 0; 
+ }
Index: gcc/testsuite/gcc.dg/torture/pr68060-2.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr68060-2.c    (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr68060-2.c    (working copy)
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do compile } */
+ 
+ void fn2 ();
+ 
+ int a, b, c;
+ 
+ void fn1()
+ {
+   for (;;) {
+       int *d;
+       fn2();
+       c = 0;
+       for (; c <= 3; c++) {
+         *d ^= 9;
+         b = 0;
+         for (; b <= 3; b++)
+           *d ^= a;
+       }
+   }
+ }

Reply via email to