Open Quuxplusone opened 6 years ago
Attached c.ll
(3541 bytes, text/plain): Test
CC Arnold because he authored HorizontalReduction::matchAssociativeReduction().
(In reply to Tim Shen from comment #0)
but didn't re-assocate the first instruction
acc = add first_element, second_element
toacc = add second_element, first_element
.
It should be phrased the other way around: but didn't re-assocate the first instruction acc = add second_elemnet, first_element
to acc = add first_element, second_element
.
As a result, the add sequence is v[1] + v[0] + v[2] + ... + v[31], which doesn't get vectorized.
c.ll
(3541 bytes, text/plain)Created attachment 19931 Test
Running
opt -S -slp-vectorizer $TEST_FILE
, the function gets SLP-vectorized; Runningopt -S -reassociate -slp-vectorizer $TEST_FILE
, the function doesn't get SLP-vectorized.This is because the reassociation pass re-associates instructions like
acc = add ith_element, acc
toacc = add acc, ith_element
, but didn't re-assocate the first instructionacc = add first_element, second_element
toacc = add second_element, first_element
.However, as add is associative, a smarter SLP vectorizer could have ignored the associations and vectorize the unordered adds anyway.
I'm not sure where to put the fix on.