This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]: Improve ability of PRE to detect redundancies


> With the patch attached, the loop optimizers based on the information
> provided by the scalar evolution algorithm catch more cases, and
> consequently they are executed on a wider class of programs.  The
> ivopts catches a case in which a part of its analyzer does not handle
> correctly the bsi.  I can propose the following patch that solves the
> problem, but I would ask Zdenek for a better solution:
> Index: tree-ssa-loop-ivopts.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
> retrieving revision 2.33
> diff -d -u -p -r2.33 tree-ssa-loop-ivopts.c
> --- tree-ssa-loop-ivopts.c	25 Nov 2004 22:31:09 -0000	2.33
> +++ tree-ssa-loop-ivopts.c	28 Nov 2004 13:09:51 -0000
> @@ -578,7 +578,7 @@ stmt_after_ip_normal_pos (struct loop *l
>    return stmt == last_stmt (bb);
>  }
> -/* Returns true if STMT if after the place where the original induction
> +/* Returns true if STMT is after the place where the original induction
>     variable CAND is incremented.  */
>  static bool
> @@ -596,13 +596,17 @@ stmt_after_ip_original_pos (struct iv_ca
>    /* Scan the block from the end, since the original ivs are usually
>       incremented at the end of the loop body.  */
> -  for (bsi = bsi_last (stmt_bb); ; bsi_prev (&bsi))
> +  for (bsi = bsi_last (stmt_bb); !bsi_end_p (bsi); bsi_prev (&bsi))
>      {
>        if (bsi_stmt (bsi) == cand->incremented_at)
>  	return false;
>        if (bsi_stmt (bsi) == stmt)
>  	return true;
>      }
> +
> +  /* FIXME: What happens if there are no more stmts in the BB, and
> +     none of the above exited?  */
> +  return false;
>  }

I guess this can happen if the original iv happens to be defined in
a phi node.  I am not entirely sure rest of ivopts would behave sanely then,
even if this function is fixed.  The proper fix for the function is to

if (TREE_CODE (cand->incremented_at) == PHI_NODE)
  return true;

before the loop.

On the other hand, the source of the need for the patch -- PRE creating
the wrapped around ivs -- seems like a wrong idea to me.  This
transformation seems to do nothing but increase register pressure.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]