tree-optimization/109473 - ICE with reduction epilog adjustment op

The following makes sure to carry out the reduction epilog adjustment
in the original computation type which for pointers is an unsigned
integer type.  There's a similar issue with signed vs. unsigned ops
and overflow which is fixed by this as well.

	PR tree-optimization/109473
	* tree-vect-loop.cc (vect_create_epilog_for_reduction):
	Convert scalar result to the computation type before performing
	the reduction adjustment.

	* gcc.dg/vect/pr109473.c: New testcase.
This commit is contained in:
Richard Biener 2023-04-12 10:22:08 +02:00
parent 2273fd5a6f
commit df7f55cb2a
2 changed files with 21 additions and 2 deletions

View File

@ -0,0 +1,16 @@
/* { dg-do compile } */
/* { dg-additional-options "-O" } */
struct spa_buffer {
__UINT32_TYPE__ *metas;
};
void do_port_use_buffers(struct spa_buffer **buffers, void *endptr, void *mem)
{
for (int i = 0; i < 128; i++)
{
for (int j = 0; j < 128; j++)
endptr = (void *)((__UINTPTR_TYPE__)endptr + buffers[i]->metas[j]);
if (endptr > mem)
return;
}
}

View File

@ -6297,9 +6297,12 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
{
new_temp = scalar_results[0];
gcc_assert (TREE_CODE (TREE_TYPE (adjustment_def)) != VECTOR_TYPE);
adjustment_def = gimple_convert (&stmts, scalar_type, adjustment_def);
new_temp = gimple_build (&stmts, code, scalar_type,
adjustment_def = gimple_convert (&stmts, TREE_TYPE (vectype),
adjustment_def);
new_temp = gimple_convert (&stmts, TREE_TYPE (vectype), new_temp);
new_temp = gimple_build (&stmts, code, TREE_TYPE (vectype),
new_temp, adjustment_def);
new_temp = gimple_convert (&stmts, scalar_type, new_temp);
}
epilog_stmt = gimple_seq_last_stmt (stmts);