This is an archive of the discontinued LLVM Phabricator instance.

Train vectorizer to recognize basic floating-point recurrences
AcceptedPublic

Authored by tyler.nowicki on Aug 26 2015, 4:03 PM.

Details

Summary

This patch allows the vectorizer to identify and vectorize recurrences such as (v = v + c) which are used in the loop. These differ from reductions because they are not used outside the loop.

The recurrences are treated just like reductions by the vectorizer. An epilogue is generated for each recurrence, like reduction, so its value can be picked up in the scalar-remainder loop.

There is a bug in 'Combine redundant instructions' that prevents vectorization of mul and div loops when the step is constant. So in the tests the step is an argument. I'll file a bug for that.

Diff Detail

Event Timeline

tyler.nowicki retitled this revision from to Train vectorizer to recognize basic floating-point recurrences.
tyler.nowicki updated this object.
mzolotukhin accepted this revision.Aug 26 2015, 11:36 PM
mzolotukhin edited edge metadata.

Hi Tyler,

The patch looks good to me, modulo several nitpicks (please see below).

Thanks,
Michael

include/llvm/Transforms/Utils/LoopUtils.h
171

s/Phi nodes/Phi node/

173

s/floa ting/floating/

lib/Transforms/Utils/LoopUtils.cpp
341–342

"The instruction is used in the loop but used outside the loop" - is this sentence missing something?

349–352

We can rewrite it as

BinaryOperator *Op = dyn_cast<BinaryOperator>(U);
if (!Op)
  return false;

to avoid double casting.

393–394

Please avoid redundant casting where possible.

test/Transforms/LoopVectorize/X86/recurrence.ll
3–6

Could you instead check for a vector values in the loop? Like if the loop is vectorized with factor 4, we can look for "<4 x float>" in the output - I think that's how most of the tests check whether something is vectorized. It'll allow us to get rid of !DILocation metadata and, thus, reduce the test a little.

This revision is now accepted and ready to land.Aug 26 2015, 11:36 PM

Looks like patch was not committed.