[patch, vectorizer] Fix PR tree-optimization/37194 - vectorizer cost model

Dorit Nuzman DORIT@il.ibm.com
Wed Jan 7 12:50:00 GMT 2009


>
> Hi,
>
> This patch fixes scalar outside cost calculation in vectorizer cost
model.
> Vectorizer currently handles unknown store misalignment by peeling a
> statically unknown number of scalar iterations. The cost model for such
> cases calculates scalar outside cost not for the original scalar version,
> but including run-time guards. While when the original number of
iterations
> is known and no loop versioning for alignment or aliasing is performed,
the
> decision whether to vectorize the loop can be done statically. Therefore,
> the vector cost should be compared to the cost of the original scalar
loop.
>

(and presumably the vectorizer indeed makes the decision at compile time
and does not generate a runtime test...?)

...
> @@ -141,15 +140,7 @@ vect_estimate_min_profitable_iters (loop
>        return 0;
>      }
>
> -  /* If the number of iterations is unknown, or the
> -     peeling-for-misalignment amount is unknown, we will have to
generate.
> -     a runtime test to test the loop count against the threshold.    */
> -  if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
> -      || (byte_misalign < 0))
> -    runtime_test = true;
> -
>    /* Requires loop versioning tests to handle misalignment.  */
> -
>    if (VEC_length (gimple, LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo)))
>      {
>        /*  FIXME: Make cost depend on complexity of individual check.  */
> @@ -337,7 +328,12 @@ vect_estimate_min_profitable_iters (loop
>       conditions/branch directions.  Change the estimates below to
>       something more reasonable.  */
>
> -  if (runtime_test)
> +  /* If the number of iterations is known and we do not do versioning,
we
> can
> +     decide whether to vectorize at compile time. Hence the scalar
version
> +     do not carry cost model guard costs.  */
> +  if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
> +      || VEC_length (gimple, LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo))
> +      || VEC_length (ddr_p, LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo)))
>      {

just a suggestion for a separate patch (for readability): lets have a macro
"LOOP_VERSION_FOR_ALIGNMNET" in place of the two VEC_length calls (in other
places in the vectorizer as well).

>        /* Cost model check occurs at versioning.  */
>        if (VEC_length (gimple, LOOP_VINFO_MAY_MISALIGN_STMTS
(loop_vinfo))
> @@ -345,8 +341,8 @@ vect_estimate_min_profitable_iters (loop
>         scalar_outside_cost += TARG_COND_NOT_TAKEN_BRANCH_COST;
>        else
>         {
> -         /* Cost model occurs at prologue generation.  */
> -         if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)).
> +         /* Cost model check occurs at prologue generation.  */
> +         if (LOOP_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0)

this is much more readable than it was before... thanks!>

OK for mainline,

dorit

>             scalar_outside_cost += 2 * TARG_COND_TAKEN_BRANCH_COST
>               + TARG_COND_NOT_TAKEN_BRANCH_COST;
>           /* Cost model check occurs at epilogue generation.  */
>
> Index: testsuite/gcc.dg/vect/costmodel/ppc/costmodel-pr37194.c
> ===================================================================
> --- testsuite/gcc.dg/vect/costmodel/ppc/costmodel-pr37194.c     (revision
> 0)
> +++ testsuite/gcc.dg/vect/costmodel/ppc/costmodel-pr37194.c     (revision
> 0)
> @@ -0,0 +1,28 @@
> +/* { dg-require-effective-target vect_float } */
> +/* { dg-do compile } */
> +
> +#include <stdlib.h>}
> +#include "../../tree-vect.h"
> +
> +__attribute__ ((noinline)) void
> +ggSpectrum_Set8(float * data, float d)
> +{
> +   int i;
> +
> +   for (i = 0; i < 8; i++)
> +      data[i] = d;
> +}
> +}
> +__attribute__ ((noinline)) void
> +ggSpectrum_Set20(float * data, float d)
> +{
> +   int i;
> +
> +   for (i = 0; i < 20; i++)
> +      data[i] = d;
> +}
> +}
> +/* { dg-final { scan-tree-dump-times "vectorization not profitable" 1
> "vect" } } */
> +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } }
*/
> +/* { dg-final { cleanup-tree-dump "vect" } } */
> +
>



More information about the Gcc-patches mailing list