https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113326
Bug ID: 113326
Summary: Optimize vector shift with constant delta on
shifting-count operand
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: fxue at os dot amperecomputing.com
Target Milestone: ---
For shift by induction variable, loop vectorization could generate a series of
vector shifts, whose shifting-count operands are advanced by constant delta. We
could use result of the first vector shift as base, and transform others to be
vector shift on the result by scalar delta, which would eliminate non-uniform
shift vector count constant, and thereby save a load on most architectures.
int test(int array[16]);
int foo(int value)
{
int array[16];
for (int i = 0; i < 16; i++)
array[i] = value >> i;
return test(array);
}
// Current
vect_value = { value, value, value, value };
vect_shift_0 = vect_value >> { 0, 1, 2, 3 };
vect_shift_1 = vect_value >> { 4, 5, 6, 7 };
vect_shift_2 = vect_value >> { 8, 9, 10, 11 };
vect_shift_3 = vect_value >> { 12, 13, 14, 15 };
// To be optimized to
vect_value = { value, value, value, value };
vect_shift_0 = vect_value >> { 0, 1, 2, 3 };
vect_shift_1 = vect_shift_0 >> { 4, 4, 4, 4 };
vect_shift_2 = vect_shift_0 >> { 8, 8, 8, 8 };
vect_shift_3 = vect_shift_0 >> { 12, 12, 12, 12 };