Hi all, looking for some feedback on this, one thing I would like to draw attention to is the fact that this pattern requires 2 separate dependent reductions in the epilogue. The accumulator vector for the maximum/minimum elements can be reduced to a scalar result trivially with a min/max, but getting the index from accumulator vector of indices is more complex and requires using the position of the maximum/minimum scalar result value within the accumulator vector to create a mask.
The given solution works but it's slightly messy.
vect_create_epilogue_for_reduction creates the epilogue for one vectorized
scalar stmt at a time. This modification makes one
invocation create the epilogue for both related stmts and marks the other as
'done'. Alternate suggestions are welcome.
Joel
[vect] Support min/max + index pattern
Add the capability to vect-loop to support the following pattern.
for (int i = 0; i < n; i ++)
{
if (data[i] < best)
{
best = data[i];
best_i = i;
}
}
gcc/ChangeLog:
* tree-vect-loop.c (vect_reassociating_reduction_simple_p): New
function.
(vect_recog_minmax_index_pattern): New function.
(vect_is_simple_reduction): Add multi_use_reduction case.
(vect_create_epilog_for_reduction): Add minmax+index epilogue handling.
minmax.patch
Description: minmax.patch
