On Fri, Apr 18, 2008 at 9:34 AM, Sandeep Maram <[EMAIL PROTECTED]> wrote: > Hi, > > Consider the 2 for loops given below. > > for (i = 0; i < N ; i++) > { > a[i]= 1; > } > > for (i = 0; i < N ; i++) > { > j = j+a[i]; > } > > The headers of these 2 loops are bb_3, bb_6 respectively. They are as > follows. > > bb_3 (preds = {bb_4 bb_2 }, succs = {bb_4 bb_5 }) > { > <bb 3>: > # a_27 = PHI <a_18(4), a_17(D)(2)> > # i_24 = PHI <i_7(4), 0(2)> > # a_18 = VDEF <a_27> { a } > a[i_24] = 1; > i_7 = i_24 + 1; > if (i_7 <= 999) > goto <bb 4>; > else > goto <bb 5>; > > } > > bb_6 (preds = {bb_5 bb_7 }, succs = {bb_7 bb_8 }) > { > <bb 6>: > # j_26 = PHI <0(5), j_12(7)> > # i_25 = PHI <0(5), i_13(7)> > # VUSE <a_18> { a } > > D.1189_10 = a[i_25]; > D.1190_11 = (unsigned int) D.1189_10; > j_12 = D.1190_11 + j_26; > i_13 = i_25 + 1; > if (i_13 <= 999) > goto <bb 7>; > else > goto <bb 8>; > > } > > I am transfering statements from bb_6 to bb_3 using code - > > for (bsi = bsi_start (loop_a->header); !bsi_end_p (bsi);) > { > if ((TREE_CODE (bsi_stmt (bsi)) != LABEL_EXPR) && (TREE_CODE > (bsi_stmt (bsi)) != COND_EXPR)) > { > bsi_move_before (&bsi, &bsi_b_last); > } > else > { > bsi_next (&bsi); > } > } > > After this the two BBs look like - > > bb_6 (preds = {bb_5 bb_7 }, succs = {bb_7 bb_8 }) > { > <bb 6>: > # j_26 = PHI <0(5), j_12(7)> > # i_25 = PHI <0(5), i_13(7)> > if (i_13 <= 999) > goto <bb 7>; > else > goto <bb 8>; > > } > > bb_3 (preds = {bb_4 bb_2 }, succs = {bb_4 bb_5 }) > { > <bb 3>: > # a_27 = PHI <a_18(4), a_17(D)(2)> > # i_24 = PHI <i_7(4), 0(2)> > # a_18 = VDEF <a_27> { a } > a[i_24] = 1; > # VUSE <a_18> { a } > > D.1189_10 = a[i_25]; > D.1190_11 = (unsigned int) D.1189_10; > j_12 = D.1190_11 + j_26; > i_13 = i_25 + 1; > i_7 = i_24 + 1; > if (i_7 <= 999) > goto <bb 4>; > else > goto <bb 5>; > > } > > The iterator variables for the 2 loops are i_24, i_25 respectively. So > when the statements are transferred, there is a problem with i_25 in > bb_3 . How can I change the name of i_25 to i_24 ?
You can for example add a copy instruction i_25 = i_24 at the top of the new loop (but you have to remove the existing definition for i_25 in the old loop then). Otherwise you can change and walk operands of trees using the immediate use iterators and SET_USE. Just grep for it and you'll find example uses. Richard.