[patch] for PRs 27639 and 26719

Zdenek Dvorak rakdver@atrey.karlin.mff.cuni.cz
Wed Jul 5 21:10:00 GMT 2006


Hello,

> [Sorry for the longish delay]
> 
> > here is the patch I'd consider correct.  I still need to test it (I
> > forgot to include ada in regtesting this time).
> 
> Thanks for the patch.  But I think it is too broad and I'd rather follow 
> Jeff's middle-ground approach.  Revised proposition attached.

I tought you said it is forbidden to do arithmetics directly in the
subtype?  If that is the case, you would also need to make changes to
the most of the optimizers that use scalar evolutions to handle these
scevs specially (and I do not think you would gain too much, as all the
arithmetics should be performed in the supertype anyway, if I understand
well what you told before).

Zdenek

> 
> 	* tree-ssa-loop-niter.c (partial_range_type_p): New predicate.
> 	(scev_probably_wraps_p): Do not rely on overflow semantics if
> 	the type has only a partial range.
> 	* tree-chrec.c (convert_affine_scev): Likewise.
> 	* tree-flow.h (partial_range_type_p): Declare.
> 
> 
> -- 
> Eric Botcazou

> Index: tree-chrec.c
> ===================================================================
> --- tree-chrec.c	(revision 114982)
> +++ tree-chrec.c	(working copy)
> @@ -1134,7 +1134,9 @@ convert_affine_scev (struct loop *loop, 
>    must_check_src_overflow = TYPE_PRECISION (ct) < TYPE_PRECISION (type);
>  
>    enforce_overflow_semantics = (use_overflow_semantics
> -				&& nowrap_type_p (type));
> +				&& nowrap_type_p (type)
> +				&& !partial_range_type_p (type));
> +
>    if (enforce_overflow_semantics)
>      {
>        /* We can avoid checking whether the result overflows in the following
> Index: tree-flow.h
> ===================================================================
> --- tree-flow.h	(revision 114740)
> +++ tree-flow.h	(working copy)
> @@ -813,6 +813,7 @@ bool scev_probably_wraps_p (tree, tree, 
>  bool convert_affine_scev (struct loop *, tree, tree *, tree *, tree, bool);
>  
>  bool nowrap_type_p (tree);
> +bool partial_range_type_p (tree type);
>  enum ev_direction {EV_DIR_GROWS, EV_DIR_DECREASES, EV_DIR_UNKNOWN};
>  enum ev_direction scev_direction (tree);
>  
> Index: tree-ssa-loop-niter.c
> ===================================================================
> --- tree-ssa-loop-niter.c	(revision 114982)
> +++ tree-ssa-loop-niter.c	(working copy)
> @@ -1951,6 +1951,19 @@ nowrap_type_p (tree type)
>    return false;
>  }
>  
> +/* Returns true if the arithmetics in TYPE doesn't cover the full range
> +   of its underlying representation.  */
> +
> +bool
> +partial_range_type_p (tree type)
> +{
> +  /* Be conservative and treat all subtypes alike.  */
> +  if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type))
> +    return true;
> +
> +  return false;
> +}
> +
>  /* Return false only when the induction variable BASE + STEP * I is
>     known to not overflow: i.e. when the number of iterations is small
>     enough with respect to the step and initial condition in order to
> @@ -1997,7 +2010,9 @@ scev_probably_wraps_p (tree base, tree s
>  
>    /* If we can use the fact that signed and pointer arithmetics does not
>       wrap, we are done.  */
> -  if (use_oveflow_semantics && nowrap_type_p (type))
> +  if (use_oveflow_semantics
> +      && nowrap_type_p (type)
> +      && !partial_range_type_p (type))
>      return false;
>  
>    /* Otherwise, compute the number of iterations before we reach the



More information about the Gcc-patches mailing list