From 61226dc8a6eb0371d39f437813fbb3279d87f723 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Tue, 2 Mar 2010 10:22:30 +0000 Subject: [PATCH] Fix PR42640: Correctly initialize the value of the new induction variable. 2010-03-02 Reza Yazdani PR middle-end/42640 * tree-loop-distribution.c (update_phis_for_loop_copy): Replaced the assignment from the new induction variable to the assignment of the value from the original loop PHI function. * gcc.dg/tree-ssa/pr42640.c: New. From-SVN: r157161 --- gcc/ChangeLog | 13 ++++++-- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/tree-ssa/pr42640.c | 58 +++++++++++++++++++++++++++++++++ gcc/tree-loop-distribution.c | 4 +-- 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr42640.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 47e217f..9e9755a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2010-03-02 Reza Yazdani + + PR middle-end/42640 + * tree-loop-distribution.c (update_phis_for_loop_copy): Replaced + the assignment from the new induction variable to the assignment + of the value from the original loop PHI function. + 2010-03-01 Janis Johnson Daniel Jacobowitz @@ -27,7 +34,7 @@ 2010-03-01 Christian Bruel * except.c (dw2_build_landing_pads): set LABEL_PRESERVE_P. - + 2010-03-01 H.J. Lu * config/i386/linux64.h (ASM_SPEC): Use SPEC_32 and SPEC_64. @@ -47,7 +54,7 @@ 64-bit, SPARC and x86. (sol_gt_pch_get_address): New function. -2010-03-01 Marco Poletti +2010-03-01 Marco Poletti * toplev.h (inform_n, error_n): Declare. * diagnostic.c (inform_n, error_n): New function. @@ -133,7 +140,7 @@ * doc/standards.texi: Likewise. * doc/extend.texi: Likewise. * doc/trouble.texi: Likewise. - * doc/cppopts.texi: Likewise. + * doc/cppopts.texi: Likewise. * doc/install.texi: Likewise. * c.opt (std=c90,std=gnu90): New options. * c-opts.c (c_common_handle_option): Handle them. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6e72856..63ceb9a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-03-02 Reza Yazdani + + PR middle-end/42640 + * gcc.dg/tree-ssa/pr42640.c: New. + 2010-03-01 Richard Guenther PR tree-optimization/43220 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr42640.c b/gcc/testsuite/gcc.dg/tree-ssa/pr42640.c new file mode 100644 index 0000000..70807c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr42640.c @@ -0,0 +1,58 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -ftree-loop-distribution" } */ + +/* Checks if loop distribution works correctly if the subscript used + is assigned to a loop invariant value. */ + +extern void abort (void); +struct S { int a; int b; int c; }; + +int get_rr_node_index (int i) +{ + return i; +} + +struct S nodes[8]; +struct S *rr_node = nodes; +volatile int io_rat = 2; +void +doit (int i, int j) +{ + int s_node, p_node, inode, ipad, iloop; + + for (ipad = 0; ipad < io_rat; ipad++) + { + p_node = get_rr_node_index (ipad+2); + inode = get_rr_node_index (ipad); + + for (iloop = 1; iloop <= 2; iloop++) + { + rr_node[inode].a = i; + rr_node[inode].b = j; + rr_node[inode].c = ipad; + inode = p_node; + } + } +} + +int +main () +{ + int i; + + doit (1, 2); + + if (rr_node[0].a != rr_node[1].a + || rr_node[2].a != rr_node[3].a + || rr_node[1].a != 1 + || rr_node[0].b != rr_node[1].b + || rr_node[2].b != rr_node[3].b + || rr_node[1].b != 2 + || rr_node[0].c != 0 + || rr_node[1].c != 1 + || rr_node[2].c != 0 + || rr_node[3].c != 1) + abort (); + + return 0; +} diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c index 13ac7ea..920ab8c 100644 --- a/gcc/tree-loop-distribution.c +++ b/gcc/tree-loop-distribution.c @@ -118,8 +118,8 @@ update_phis_for_loop_copy (struct loop *orig_loop, struct loop *new_loop) if (!new_ssa_name) /* This only happens if there are no definitions inside the - loop. Use the phi_result in this case. */ - new_ssa_name = PHI_RESULT (phi_new); + loop. Use the the invariant in the new loop as is. */ + new_ssa_name = def; } else /* Could be an integer. */ -- 2.7.4