Re: How to handle loop iterator variable?

2008-05-19 Thread Sandeep Maram
Hi,

 My function is working properly for the below case -

for (i = 1; i  N ; i++)
{
  a[i] = 1;
}
  for (i = 1; i  N ; i++)
{
  j = a[i];
}

But I am required to add additional phi node for j in the following case -

for (i = 1; i  N ; i++)
{
  a[i] = 1;
}
  for (i = 1; i  N ; i++)
{
  j = j + a[i];
}

  I am trying to understand how it is done in create_iv. I have tried
using merge_blocks() of cfghooks.c to fuse the loop headers. Using
code

/* The following function fuses two loops.  */

void
fuse_loops (struct loop *loop_a, struct loop *loop_b)
{
  basic_block *bbs_a, *bbs_b;
  struct loop *new_loop;
  bbs_a = get_loop_body (loop_a);
  bbs_b = get_loop_body (loop_b);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10);
  merge_blocks (bbs_b[0], bbs_a[0]);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10);
  cancel_loop_tree (loop_a);

}

 But the I get an internal compiler error -

loop.c: In function 'main':
loop.c:8: internal compiler error: in single_succ_edge, at basic-block.h:638

The function merge_blocks()  merges blocks only with single successors
and predecessors. But the blocks in loops have 2 each.

Can you please suggest what is the right thing to do here?

Thanks,
Sandeep.


Re: How to handle loop iterator variable?

2008-05-15 Thread Sandeep Maram
 In lambda-code.c:1858 you have some code that does a similar renaming:

 FOR_EACH_IMM_USE_STMT (stmt, imm_iter, oldiv_def)
  FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
propagate_value (use_p, newiv);


The function replace_uses_by() also does the same renaming and it is
suitable in my case. So I have used it and renamed the iterator
variable. The problem with the iterator variable is solved.

Now I have deleted all the PHI nodes of loop_a and transferred and all
the statements one by one to loop_b.
So the statement
j_12 = D.1190_11 + j_24;
is now present in loop_b, but I am unable to create the phi node for
it in loop_b. Can you please tell me how can I create phi node for
j_24 ?

I am attaching the patch and .c file.

Thanks,
Sandeep.


/* Loop fusion. */

/* This pass performs loop fusion: for example, the loops

	|loop_1
	|  A[i] = ...
	|endloop_1


	|loop_2
	|  ... = A[i]
	|endloop_2

   that becomes after fusion:

	|loop_1
	|  A[i] = ...
	|  ... = A[i]
	|endloop_1

*/

#include config.h
#include system.h
#include coretypes.h
#include tm.h
#include ggc.h
#include tree.h
#include target.h

#include rtl.h
#include basic-block.h
#include diagnostic.h
#include tree-flow.h
#include tree-dump.h
#include timevar.h
#include cfgloop.h
#include expr.h
#include optabs.h
#include tree-chrec.h
#include tree-data-ref.h
#include tree-scalar-evolution.h
#include tree-pass.h
#include lambda.h
#include langhooks.h
#include tree-vectorizer.h




/* Returns true when a given loop is a parallel loop.  */

static bool
is_parallel_loop (struct loop *loop)
{
  VEC (ddr_p, heap) * dependence_relations;
  VEC (data_reference_p, heap) * datarefs;
  lambda_trans_matrix trans;
  bool ret = false;
  
  /* If the loop can be reversed, the iterations are independent.  */
  datarefs = VEC_alloc (data_reference_p, heap, 10);
  dependence_relations = VEC_alloc (ddr_p, heap, 10 * 10);
  compute_data_dependences_for_loop (loop, true, datarefs, dependence_relations);
  trans = lambda_trans_matrix_new (1, 1);
  LTM_MATRIX (trans)[0][0] = -1;

  if (lambda_transform_legal_p (trans, 1, dependence_relations))
{
  ret = true;
}

  free_dependence_relations (dependence_relations);
  free_data_refs (datarefs);
  if (ret == true)
fprintf (dump_file,  loop %d is a parallel loop\n , loop-num);
  return ret;
}

/* Returns true when a given loop is a sequential loop.  */

static bool
is_sequential_loop (struct loop *loop)
{
  if (is_parallel_loop (loop))
return false;
  else
return true;
}

/* Returns true if there is no fusion preventing constraint between two given loops.  */

static bool
no_fusion_preventing_constraint (struct loop *loop_a, struct loop *loop_b)
{
  bool ret = true;
  struct loop *father_loop;
  father_loop = find_common_loop (loop_a, loop_b);
  struct graph *rdg_father;
  rdg_father = build_rdg (father_loop);
  struct graph *rdg_a;
  rdg_a = build_rdg (loop_a);
  struct graph *rdg_b;
  rdg_b = build_rdg (loop_b);
  return ret;
}

/* Returns true when two loops can be fused.  */

static bool
can_fuse_loops (struct loop *loop_a, struct loop *loop_b)
{
  if ((is_parallel_loop (loop_a)  is_parallel_loop (loop_b)  no_fusion_preventing_constraint (loop_a, loop_b)) || 
  (is_sequential_loop (loop_a)  is_sequential_loop (loop_b)  no_fusion_preventing_constraint (loop_a, loop_b)))
{
  fprintf (dump_file,  can fuse loops %d %d , loop_a-num, loop_b-num);
  return true;
}

  return false;
}

/* The following function fuses two loops.  */

void
fuse_loops2 (struct loop *loop_a, struct loop *loop_b)
{
  basic_block *bbs_a, *bbs_b;
  struct loop *new_loop;
  bbs_a = get_loop_body (loop_a);
  bbs_b = get_loop_body (loop_b);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10); 
  tree_merge_blocks (bbs_b[0], bbs_a[0]);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10); 
  cancel_loop_tree (loop_a);
  
}


/* The following function fuses two loops.  */

void
fuse_loops (struct loop *loop_a, struct loop *loop_b)
{
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10); 
  block_stmt_iterator bsi_a, bsi_a_last, bsi_b, bsi_b_last, bsi;
  bsi_b_last = bsi_last (loop_b-header);
  bsi_prev (bsi_b_last);
  tree phi, prev = NULL_TREE, next, use, def;

  /* Detects the iterator variable of loop_b.  */
  for (phi = phi_nodes (loop_b-header);
   phi;) 
{
  next = PHI_CHAIN (phi);
  use = PHI_RESULT (phi);
  phi = next;
} 

  /* Detects the iterator variable of loop_a.  */
  for (phi = phi_nodes (loop_a-header);
   phi;) 
{
  next = PHI_CHAIN (phi);
  def = PHI_RESULT (phi);
  phi = next;
} 
  
  /*for (phi = phi_nodes (loop_a-header);
   phi;)
{
  next = PHI_CHAIN (phi);
  create_phi_node (SSA_NAME_VAR (PHI_RESULT (phi)), loop_b-header);
  phi = next;
} */

  /* Replaces the itaerator variable of loop_a with that of loop_b.  */
  for (phi = phi_nodes (loop_a-header);
   phi;) 
{
  next = PHI_CHAIN (phi);
  replace_uses_by 

Fwd: How to handle loop iterator variable?

2008-05-15 Thread Sandeep Maram
-- Forwarded message --
From: Sandeep Maram [EMAIL PROTECTED]
Date: Thu, May 15, 2008 at 6:46 PM
Subject: Re: How to handle loop iterator variable?
To: Sebastian Pop [EMAIL PROTECTED]
Cc: gcc@gcc.gnu.org


 In lambda-code.c:1858 you have some code that does a similar renaming:

 FOR_EACH_IMM_USE_STMT (stmt, imm_iter, oldiv_def)
  FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
propagate_value (use_p, newiv);


Hi,

  In my previous mail I have missed some details. Please ignore it and
consider this one.

  The function replace_uses_by() also does the same renaming and it is
suitable in my case. So I have used it and renamed the iterator
variable. The problem with the iterator variable is solved.

  Now I have deleted all the PHI nodes of loop_a and transferred and all
the statements one by one to loop_b in the function fuse_loops().
So the statement
j_12 = D.1190_11 + j_24;
is now present in loop_b, but I am unable to create the phi node for
it in loop_b. I tried to do so using
for (phi = phi_nodes (loop_a-header);
   phi;)
{
  next = PHI_CHAIN (phi);
  create_phi_node (SSA_NAME_VAR (PHI_RESULT (phi)), loop_b-header);
  phi = next;
}
in fuse_loops() but the phinode is created for j_2 instead of j_24.
Can you please tell me how can I create phi node for
j_24 ?

I am attaching the patch and .c file.

Thanks,
Sandeep.


/* Loop fusion. */

/* This pass performs loop fusion: for example, the loops

	|loop_1
	|  A[i] = ...
	|endloop_1


	|loop_2
	|  ... = A[i]
	|endloop_2

   that becomes after fusion:

	|loop_1
	|  A[i] = ...
	|  ... = A[i]
	|endloop_1

*/

#include config.h
#include system.h
#include coretypes.h
#include tm.h
#include ggc.h
#include tree.h
#include target.h

#include rtl.h
#include basic-block.h
#include diagnostic.h
#include tree-flow.h
#include tree-dump.h
#include timevar.h
#include cfgloop.h
#include expr.h
#include optabs.h
#include tree-chrec.h
#include tree-data-ref.h
#include tree-scalar-evolution.h
#include tree-pass.h
#include lambda.h
#include langhooks.h
#include tree-vectorizer.h




/* Returns true when a given loop is a parallel loop.  */

static bool
is_parallel_loop (struct loop *loop)
{
  VEC (ddr_p, heap) * dependence_relations;
  VEC (data_reference_p, heap) * datarefs;
  lambda_trans_matrix trans;
  bool ret = false;
  
  /* If the loop can be reversed, the iterations are independent.  */
  datarefs = VEC_alloc (data_reference_p, heap, 10);
  dependence_relations = VEC_alloc (ddr_p, heap, 10 * 10);
  compute_data_dependences_for_loop (loop, true, datarefs, dependence_relations);
  trans = lambda_trans_matrix_new (1, 1);
  LTM_MATRIX (trans)[0][0] = -1;

  if (lambda_transform_legal_p (trans, 1, dependence_relations))
{
  ret = true;
}

  free_dependence_relations (dependence_relations);
  free_data_refs (datarefs);
  if (ret == true)
fprintf (dump_file,  loop %d is a parallel loop\n , loop-num);
  return ret;
}

/* Returns true when a given loop is a sequential loop.  */

static bool
is_sequential_loop (struct loop *loop)
{
  if (is_parallel_loop (loop))
return false;
  else
return true;
}

/* Returns true if there is no fusion preventing constraint between two given loops.  */

static bool
no_fusion_preventing_constraint (struct loop *loop_a, struct loop *loop_b)
{
  bool ret = true;
  struct loop *father_loop;
  father_loop = find_common_loop (loop_a, loop_b);
  struct graph *rdg_father;
  rdg_father = build_rdg (father_loop);
  struct graph *rdg_a;
  rdg_a = build_rdg (loop_a);
  struct graph *rdg_b;
  rdg_b = build_rdg (loop_b);
  return ret;
}

/* Returns true when two loops can be fused.  */

static bool
can_fuse_loops (struct loop *loop_a, struct loop *loop_b)
{
  if ((is_parallel_loop (loop_a)  is_parallel_loop (loop_b)  no_fusion_preventing_constraint (loop_a, loop_b)) || 
  (is_sequential_loop (loop_a)  is_sequential_loop (loop_b)  no_fusion_preventing_constraint (loop_a, loop_b)))
{
  fprintf (dump_file,  can fuse loops %d %d , loop_a-num, loop_b-num);
  return true;
}

  return false;
}

/* The following function fuses two loops.  */

void
fuse_loops2 (struct loop *loop_a, struct loop *loop_b)
{
  basic_block *bbs_a, *bbs_b;
  struct loop *new_loop;
  bbs_a = get_loop_body (loop_a);
  bbs_b = get_loop_body (loop_b);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10); 
  tree_merge_blocks (bbs_b[0], bbs_a[0]);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10); 
  cancel_loop_tree (loop_a);
  
}


/* The following function fuses two loops.  */

void
fuse_loops (struct loop *loop_a, struct loop *loop_b)
{
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10); 
  block_stmt_iterator bsi_a, bsi_a_last, bsi_b, bsi_b_last, bsi;
  bsi_b_last = bsi_last (loop_b-header);
  bsi_prev (bsi_b_last);
  tree phi, prev = NULL_TREE, next, use, def;

  /* Detects the iterator variable of loop_b.  */
  for (phi = phi_nodes (loop_b-header);
   phi;) 
{
  next = PHI_CHAIN (phi

How to handle loop iterator variable?

2008-05-09 Thread Sandeep Maram
Hi,

Consider 2 for loops as given below.

for (i = 1; i  N ; i++)
{
  a[i] = 1;
}
  for (i = 1; i  N ; i++)
{
  j = j + a[i];
}

Their corresponding GIMPLE code looks like.

loop_2 (header = 6, latch = 7, niter = , upper_bound = 999, estimate = 999)
{
  bb_6 (preds = {bb_5 bb_7 }, succs = {bb_7 bb_8 })
  {
  bb 6:
# j_24 = PHI 0(5), j_12(7)
# i_23 = PHI 1(5), i_13(7)
# VUSE a_19 { a }
D.1189_10 = a[i_23];
D.1190_11 = (unsigned int) D.1189_10;
j_12 = D.1190_11 + j_24;
i_13 = i_23 + 1;
if (i_13 = 999)
  goto bb 7;
else
  goto bb 8;

  }
  bb_7 (preds = {bb_6 }, succs = {bb_6 })
  {
  bb 7:
goto bb 6;

  }
}
loop_1 (header = 3, latch = 4, niter = , upper_bound = 999, estimate = 999)
{
  bb_3 (preds = {bb_4 bb_2 }, succs = {bb_4 bb_5 })
  {
  bb 3:
# a_25 = PHI a_19(4), a_18(2)
# i_22 = PHI i_7(4), 1(2)
# a_19 = VDEF a_25 { a }
a[i_22] = 1;
i_7 = i_22 + 1;
if (i_7 = 999)
  goto bb 4;
else
  goto bb 5;

  }
  bb_4 (preds = {bb_3 }, succs = {bb_3 })
  {
  bb 4:
goto bb 3;

  }
}

Now I have transferred all statements from loop_2 to loop_1. i.e from
bb_6 to bb_3.
Using code :

 block_stmt_iterator bsi_a, bsi_a_last, bsi_b, bsi_b_last, bsi;
  bsi_b = bsi_start (loop_b-header);
  bsi_b_last = bsi_last (loop_b-header);
  bsi_prev (bsi_b_last);

  /* Transfer all the statements one by one.  */
  for (bsi = bsi_start (loop_a-header); !bsi_end_p (bsi);)
{
if ((TREE_CODE (bsi_stmt (bsi)) != COND_EXPR)  (TREE_CODE
(bsi_stmt (bsi)) != LABEL_EXPR))
   {
 update_stmt (bsi_stmt (bsi));
 bsi_move_before (bsi, bsi_b_last);
 fprintf (stderr,  transferred one statement. \n );
 fprintf (dump_file,  transferred one statement. \n );
 update_stmt (bsi_stmt (bsi));
   }
else
   {
 bsi_next (bsi);
   }
 }


Now the GIMPLE codes look like.


 loop_2 (header = 6, latch = 7, niter = , upper_bound = 999, estimate = 999)
{
  bb_6 (preds = {bb_5 bb_7 }, succs = {bb_7 bb_8 })
  {
  bb 6:
# j_24 = PHI 0(5), j_12(7)
# i_23 = PHI 1(5), i_13(7)
if (i_13 = 999)
  goto bb 7;
else
  goto bb 8;

  }
  bb_7 (preds = {bb_6 }, succs = {bb_6 })
  {
  bb 7:
goto bb 6;

  }
}
loop_1 (header = 3, latch = 4, niter = , upper_bound = 999, estimate = 999)
{
  bb_3 (preds = {bb_4 bb_2 }, succs = {bb_4 bb_5 })
  {
  bb 3:
# a_25 = PHI a_19(4), a_18(2)
# i_22 = PHI i_7(4), 1(2)
# a_19 = VDEF a_25 { a }
a[i_22] = 1;
# VUSE a_19 { a }
D.1189_10 = a[i_23];
D.1190_11 = (unsigned int) D.1189_10;
j_12 = D.1190_11 + j_24;
i_13 = i_23 + 1;
i_7 = i_22 + 1;
if (i_7 = 999)
  goto bb 4;
else
  goto bb 5;

  }
  bb_4 (preds = {bb_3 }, succs = {bb_3 })
  {
  bb 4:
goto bb 3;

  }
}

Now I get an internal compiler error saying
error: definition in block 6 does not dominate use in block 3
for SSA_NAME: i_23 in statement:
# VUSE a_19
D.1189_10 = a[i_23];

i_23 is the loop iterator of loop_2 . i_22 is the loop iterator of loop_1.

How can I rename i_23 as i_22?

Thanks,
Sandeep.


Re: Moving statements from one BB to other BB.

2008-04-18 Thread Sandeep Maram
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 ?

Thanks,
Sandeep.


Re: Moving statements from one BB to other BB.

2008-04-17 Thread Sandeep Maram
On Tue, Apr 15, 2008 at 11:40 PM, Diego Novillo [EMAIL PROTECTED] wrote:

 On 4/15/08 1:34 PM, Zdenek Dvorak wrote:

  Hi,
 
 
  
  To clarify what Richard means, your assertion that you have
 updated
  SSA information is false.
  If you had updated the SSA information, the error would not occur
 :).
 
  How exactly are you updating the ssa information?
 
  The general way to update SSA for this case would be:
 
  For each statement you have moved:
Call update_stmt (t);
 
  Then call update_ssa (TODO_update_ssa) (or instead use
  rewrite_into_loop_closed_ssa if this is a loop pass).
 
  If you do not call update_stmt in this case, update_ssa won't
 actually
  do anything.
   
 actually, it will not do anything even if he calls update_stmt, as
 the
 statements that he is moving are already in ssa form, so update_stmt
 will not mark anything for renaming.
   
   
   You are partially right (and right where it matters, that it won't fix
   the problem)
   That said, update_stmt on ssa form statements will at least reset the
   vuse/vdef back to original variables for renaming.
  
 
  I don't think so; as long as you do not introduce new vops (which you
  should not by just moving the statements), update_stmt is a no-op on
  vops too (unless something has changed since the last time I needed
  this),
 

  Right.  Moving statements in SSA form needs to introduce name-name
 mappings (eg, as is done during loop unrolling).


Yes, calling update_stmt for evry transfer and then calling update_ssa
later, didn't work. From the discussions, I understood that I have to
change the SSA names in the statements to be transfered, to the
corresponding SSA names in the destination block. Can you please tell
me , whether there are any functions that manipulate the SSA names ?

Thanks,
Sandeep.


  Diego.



Re: Moving statements from one BB to other BB.

2008-04-17 Thread Sandeep Maram
On Tue, Apr 15, 2008 at 3:00 PM, Richard Guenther
[EMAIL PROTECTED] wrote:

 On Tue, Apr 15, 2008 at 7:49 AM, Sandeep Maram [EMAIL PROTECTED] wrote:
   On Tue, Apr 15, 2008 at 10:34 AM, Daniel Berlin [EMAIL PROTECTED] wrote:
 To clarify what Richard means, your assertion that you have updated
  SSA information is false.
  If you had updated the SSA information, the error would not occur :).

  How exactly are you updating the ssa information?
  
I am calling update_ssa (TODO_update_ssa), after all the statements
are transferred.
  
  

  The general way to update SSA for this case would be:

  For each statement you have moved:
   Call update_stmt (t);

  Then call update_ssa (TODO_update_ssa) (or instead use
  rewrite_into_loop_closed_ssa if this is a loop pass).

  If you do not call update_stmt in this case, update_ssa won't actually
  do anything.

  Diego, the bsi iterators do not update the statements for you though
  it is not clear if this is a bug or not.

  The bsi iterators call update_modified_stmts, which says:

  /* Mark statement T as modified, and update it.  */
  static inline void
  update_modified_stmts (tree t)

  However, this only calls update_stmt_if_modified (IE it does not mark
  the statement as modified and update it, as it claims to).

  Sandeep, it should also suffice to call mark_stmt_modified *before*
  moving the statements (since the above routine should then update
  them).

  
Thanks. I will use update_stmt, update_ssa now.

  You need to do more than that - you appearantly are moving uses of
  SSA names to a place where its definition is not available like if you do

   b_1 = 1;
   a_1 = b_1 + 1;

  and transform this to

   a_1 = b_1 + 1;
   b_1 = 1;

  which obviously cannot work.  So updating SSA form won't help you
  and renaming the symbols will only make the verifier happy and leave
  you with wrong code.

  So you need to investigate what exactly you are doing wrong with
  your stmt movement.

I am considering two consequent fusible loops. These loops have a
single header and a single latch.  I want to move the statements in
the header of the second loop to the header of the first loop. This
function will be called only after certain constraints are met. That
is legality test is performed before fusing these loops.

I think I am transfering all the statements inside the loop correctly.
But I am doing some mistake with the iterator variable.

Thanks,
Sandeep.


  Richard.



Moving statements from one BB to other BB.

2008-04-14 Thread Sandeep Maram
Hi,

I have transferred all the statements of one BB( header of one loop)
to another BB. After that I have updated SSA information too.
But I get this error-

 definition in block 6 does not dominate use in block 3
for SSA_NAME: i_25 in statement:
# VUSE a_18
D.1189_10 = a[i_25];
loop.c:8: internal compiler error: verify_ssa failed

Can any one please tell me what is the problem?

Thanks,
Sandeep.


Re: Moving statements from one BB to other BB.

2008-04-14 Thread Sandeep Maram
On Tue, Apr 15, 2008 at 10:34 AM, Daniel Berlin [EMAIL PROTECTED] wrote:
 To clarify what Richard means, your assertion that you have updated
  SSA information is false.
  If you had updated the SSA information, the error would not occur :).

  How exactly are you updating the ssa information?

I am calling update_ssa (TODO_update_ssa), after all the statements
are transferred.


  The general way to update SSA for this case would be:

  For each statement you have moved:
   Call update_stmt (t);

  Then call update_ssa (TODO_update_ssa) (or instead use
  rewrite_into_loop_closed_ssa if this is a loop pass).

  If you do not call update_stmt in this case, update_ssa won't actually
  do anything.

  Diego, the bsi iterators do not update the statements for you though
  it is not clear if this is a bug or not.

  The bsi iterators call update_modified_stmts, which says:

  /* Mark statement T as modified, and update it.  */
  static inline void
  update_modified_stmts (tree t)

  However, this only calls update_stmt_if_modified (IE it does not mark
  the statement as modified and update it, as it claims to).

  Sandeep, it should also suffice to call mark_stmt_modified *before*
  moving the statements (since the above routine should then update
  them).


Thanks. I will use update_stmt, update_ssa now.

Best Regards,
Sandeep.

  On Mon, Apr 14, 2008 at 7:10 AM, Richard Guenther

 [EMAIL PROTECTED] wrote:


  On Mon, Apr 14, 2008 at 12:54 PM, Sandeep Maram [EMAIL PROTECTED] wrote:
 Hi,

  I have transferred all the statements of one BB( header of one loop)
  to another BB. After that I have updated SSA information too.
  But I get this error-

   definition in block 6 does not dominate use in block 3
  for SSA_NAME: i_25 in statement:
  
This is the problem.
  
  
  
  # VUSE a_18
  D.1189_10 = a[i_25];
  loop.c:8: internal compiler error: verify_ssa failed

  Can any one please tell me what is the problem?

  Thanks,
  Sandeep.

  



Re: Fusing two loops

2008-04-11 Thread Sandeep Maram
Hi Zdenek,

Thanks.

Sandeep.

On Thu, Apr 10, 2008 at 7:29 PM, Zdenek Dvorak [EMAIL PROTECTED] wrote:
 Hi,

   The error is rectified. The bug is in the function that calls fuse_loops().
   Now I am trying to transfer all the statements, using code -
  
   /* The following function fuses two loops.  */
  
   void
   fuse_loops (struct loop *loop_a, struct loop *loop_b)
   {
 debug_loop (loop_a, 10);
 debug_loop (loop_b, 10);
 block_stmt_iterator bsi_a = bsi_start (loop_a-header);
 block_stmt_iterator bsi_a_last = bsi_last (loop_a-header);
 block_stmt_iterator bsi_b = bsi_last (loop_b-header);
 while (bsi_a != bsi_a_last)
   {
 bsi_move_before (bsi_a, bsi_b);
 fprintf (stderr,  transferred one statement from loop %d to
   loop %d , loop_a-num, loop_b-num);
 bsi_next (bsi_a);
   }

  try


  bsi_b = bsi_last (loop_b-header);

  for (bsi_a = bsi_start (loop_a-header); !bsi_end_p (bsi_a); )
   {
 if (some condition)  /* you probably want to skip labels and cond_exprs */

   bsi_move_before (bsi_a, bsi_b);
 else
   bsi_next (bsi_a);
   }

  Zdenek



Fwd: Fusing two loops

2008-04-10 Thread Sandeep Maram
-- Forwarded message --
From: Sandeep Maram [EMAIL PROTECTED]
Date: Thu, Apr 10, 2008 at 11:57 AM
Subject: Re: Fusing two loops
To: Zdenek Dvorak [EMAIL PROTECTED]


Hi Zdenek,

 I have written this function

 /* The following function fuses two loops.  */

 void
 fuse_loops (struct loop *loop_a, struct loop *loop_b)
 {
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10);
  block_stmt_iterator bsi_a = bsi_start (loop_a-header);
  block_stmt_iterator bsi_b = bsi_last (loop_b-header);
  bsi_move_before (bsi_a, bsi_b);
  fprintf (stderr,  transferred one statement from loop %d to loop %d
 , loop_a-num, loop_b-num);
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10);
  cancel_loop_tree (loop_a);
 }

 It moved one statement from loop_a to loop_b. In the same way I must
 tranfer all other statements too. I get a internal compiler error at 
 cancel_loop_tree(loop_a);  . After transfering statemnts from loop_a
 to loop_b I need to delete the loop_a from current_loops . How can we
 do this?

 Thanks,
 Sandeep.



 On Fri, Apr 4, 2008 at 7:31 PM, Zdenek Dvorak [EMAIL PROTECTED] wrote:
  Hi,
 
I am trying to fuse two loops in tree level. For that, I am trying to
transfer statements in the header of one loop to the header of the
other one.
The  codehttp://rafb.net/p/fha0IG57.html   contains the 2 loops.
After moving a statement from one BB to another BB, do I need to
update any other info?
 
   you will need to update SSA form; other than that, just using bsi_move_after
   to move the relevant statements should work.
 
 
 I need to transfer all the statements of bb_6 to bb_3. Can any one
please tell me what is the exact procedure.
Can i simply use add_bb_to_loop() and add bb_6 to loop_1 ?
 
   No; in the case that you describe, moving the statements one by one is
   probably the simplest way (you could also move whole basic block, but
   it is more complicated, and since you still need to update SSA form,
   you would need to process the statements anyway).
 
   Zdenek
 


Re: Fusing two loops

2008-04-10 Thread Sandeep Maram
Hi,
The error is rectified. The bug is in the function that calls fuse_loops().
Now I am trying to transfer all the statements, using code -

/* The following function fuses two loops.  */

void
fuse_loops (struct loop *loop_a, struct loop *loop_b)
{
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10);
  block_stmt_iterator bsi_a = bsi_start (loop_a-header);
  block_stmt_iterator bsi_a_last = bsi_last (loop_a-header);
  block_stmt_iterator bsi_b = bsi_last (loop_b-header);
  while (bsi_a != bsi_a_last)
{
  bsi_move_before (bsi_a, bsi_b);
  fprintf (stderr,  transferred one statement from loop %d to
loop %d , loop_a-num, loop_b-num);
  bsi_next (bsi_a);
}
  debug_loop (loop_a, 10);
  debug_loop (loop_b, 10);
  cancel_loop_tree (loop_a);
}

After doing this I get a segmentation fault , after 3 statements of
loop_a are transferred to loop_b.

Program received signal SIGSEGV, Segmentation fault.
0x08436245 in tsi_next (i=0xb5b0) at ../../trunk/gcc/tree-iterator.h:74
74i-ptr = i-ptr-next;

Thanks,
Sandeep.

On Thu, Apr 10, 2008 at 5:57 PM, Zdenek Dvorak [EMAIL PROTECTED] wrote:
 Hi,


   I have written this function
  
   /* The following function fuses two loops.  */
  
   void
   fuse_loops (struct loop *loop_a, struct loop *loop_b)
   {
debug_loop (loop_a, 10);
debug_loop (loop_b, 10);
block_stmt_iterator bsi_a = bsi_start (loop_a-header);
block_stmt_iterator bsi_b = bsi_last (loop_b-header);
bsi_move_before (bsi_a, bsi_b);
fprintf (stderr,  transferred one statement from loop %d to loop %d
   , loop_a-num, loop_b-num);
debug_loop (loop_a, 10);
debug_loop (loop_b, 10);
cancel_loop_tree (loop_a);
   }
  
   It moved one statement from loop_a to loop_b. In the same way I must
   tranfer all other statements too. I get a internal compiler error at 
   cancel_loop_tree(loop_a); 

  where exactly (can you send me a backtrace)?  It does not seem possible
  for cancel_loop_tree to ICE, if fuse_loops is the only function that you
  call.

  Zdenek



Fusing two loops

2008-04-04 Thread Sandeep Maram
Hi,

I am trying to fuse two loops in tree level. For that, I am trying to
transfer statements in the header of one loop to the header of the
other one.
The  codehttp://rafb.net/p/fha0IG57.html   contains the 2 loops.
After moving a statement from one BB to another BB, do I need to
update any other info?
 I need to transfer all the statements of bb_6 to bb_3. Can any one
please tell me what is the exact procedure.
Can i simply use add_bb_to_loop() and add bb_6 to loop_1 ?

Thanks,
Sandeep.