This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] vectorizer cost-model: fixes and powerpc testcases
- From: Dorit Nuzman <DORIT at il dot ibm dot com>
- To: Dorit Nuzman <DORIT at il dot ibm dot com>
- Cc: gcc-patches at gcc dot gnu dot org, "Jagasia, Harsha" <harsha dot jagasia at amd dot com>
- Date: Thu, 5 Jul 2007 16:18:38 +0300
- Subject: Re: [patch] vectorizer cost-model: fixes and powerpc testcases
committed.
dorit
Dorit Nuzman/Haifa/IBM wrote on 17/06/2007 12:02:11:
> Hi,
>
> This patch adds powerpc tests for the vectorizer cost model, and
> fixes a few issues in the cost model that I discovered while playing
> with these tests:
>
> 1- The main cost model function is called twice - once during
> analysis, and once again in vect_do_peeling_for_loop_bound (to get
> the threshold that controls whether the vector loop will be
> executed). This is wrong because each time the cost model is called
> it adds the estimated costs to the STMT_VINFO_*_OF_LOOP_COST fields,
> so we get wrong inflated costs when we call it the second time. We
> really want to call it only once, and record the estimated threshold
> somewhere. This patch adds a new field for that:
> LOOP_VINFO_COST_MODEL_MIN_ITERS.
>
> 2- The cost model always adds loop-versioning costs because it
> checks whether LOOP_VINFO_MAY_MISALIGN_STMTS is not NULL, instead of
> checking that it is not empty (i.e. using VEC_length).
>
> 3- The calculation of peel_iters_prologue is wrong: it was set to
> LOOP_PEELING_FOR_ALIGNMENT which is the misalignment of the data-
> reference in bytes. Instead it should be set to:
> min (niters, vs - mis)
> ...where 'vs' is the vector size in number of elements, and 'mis' is
> the misalignment in number of elements.
>
> 4- Adding the branch-costs due to prologue/epilogue creation is done
> before peel_iters_prologue/epilogue are accurately computed (so we
> may not add epilogue branch-costs although later on we determine
> that an epilogue will be generated). This patch moves it to after we
> compute peel_iters_prologue/epilogue.
>
> 5- Turns out we're not considering the cost of creating a vector
> from a scalar when we have operations that use constant or invariant
> values. This patch adds a new cost - TARG_SCALAR_TO_VEC_COST, and
> also passes the def-type "dt" (which says whether a use is
> constant/invariant/defined in the loop, etc) to
> vect_model_simple_cost and vect_model_store_cost so that these
> functions could add the TARG_SCALAR_TO_VEC_COST when appropriate.
>
> 6- We now always print that "vectorization may not be profitable".
> This is changed to be printed only when the cost model returned a
> non-zero threshold, and the number of iterations is unknown.
>
> Harsha, I had to change the expected dg-final check in one of the
> i386 tests due to the changes above. There maybe some things need to
> be modified for the x86_64 tests too - could you take a look at that?
>
> Bootstrapped on i386-linux and powerpc-linux
> Tested on the vectorizer testcases on powerpc-linux
> Passed full regression testing on i386-linux.
>
> This patch is just bug fixes, but I'm not sure if it counts as a
> "regression fix" and can be committed to mainline during the current
freeze?
>
> thanks,
> dorit
>
> ChangeLogs:
>
> * tree-vectorizer.c (new_loop_vec_info): Initialize
> LOOP_VINFO_COST_MODEL_MIN_ITERS.
> * tree-vectorizer.h (_loop_vec_info): Added new filed
> min_profitable_iters.
> (LOOP_VINFO_COST_MODEL_MIN_ITERS): New access macro to abovenew
field.
> (TARG_SCALAR_TO_VEC_COST): Define cost of scalar to vector
operation.
> * tree-vect-analyze.c (vect_analyze_operations): Set
> LOOP_VINFO_COST_MODEL_MIN_ITERS.
> * tree-vect-transform.c (vect_estimate_min_profitable_iters): Use
> VEC_length to determine if there are any
> LOOP_VINFO_MAY_MISALIGN_STMTS.
> Fix calculation of peel_iters_prologue. Move consideration of
epilogue
> and prologue cost to after they are computed.
> (vect_model_induction_cost): Use TARG_SCALAR_TO_VEC_COST instead
of
> TARG_VEC_STMT_COST.
> (vect_model_simple_cost): Takes additional argument dt. Consider
cost
> of creating vectors from scalars according to dt.
> (vect_model_store_cost): Likewise.
> (vectorizable_call): Use dt array instead of scalar dt. Call
> vect_model_simple_cost with additional argument dt.
> (vectorizable_assignment): Likewise.
> (vectorizable_operation): Likewise.
> (vectorizable_type_demotion): Likewise.
> (vectorizable_type_promotion): Likewise.
> (vectorizable_store): Use dt array instead of scalar dt. Call
> vect_model_store_cost with additional argument dt.
> (vect_do_peeling_for_loop_bound): Don't call
> vect_estimate_min_profitable_iters. Instead, lookup
> LOOP_VINFO_COST_MODEL_MIN_ITERS. Don't always print
> "may not be profitable".
>
> * gcc.dg/vect/costmodel/ppc: New directory.
> * gcc.dg/vect/costmodel/ppc/ppc-costmodel-vect.exp: New.
> * gcc.dg/vect/costmodel/ppc/costmodel-fast-math-vect-
> pr29925.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-31b.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-31c.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-31d.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-33.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-76a.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-76b.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-68a.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-68b.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-68c.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-68d.c: New test.
> * gcc.dg/vect/costmodel/ppc/costmodel-vect-reduc-1char.c: New
test.
> * gcc.dg/vect/costmodel/i386/costmodel-vect-68.c: Now vectorized.
>
> #### costmodelfixes.june16.txt has been deleted