This is an archive of the discontinued LLVM Phabricator instance.

[LoopVectorize] Don't use strict reductions when reordering is allowed
ClosedPublic

Authored by kmclaughlin on Jun 7 2021, 7:29 AM.

Details

Summary

If the -enable-strict-reductions flag is set to true, then currently we will
always choose to vectorize the loop with strict in-order reductions. This is
not necessary where we allow the reordering of FP operations, such as
when loop hints are passed via metadata.

This patch moves useOrderedReductions so that we can also check whether
loop hints allow reordering, in which case we should use the default
behaviour of vectorizing with unordered reductions.

Diff Detail

Event Timeline

kmclaughlin created this revision.Jun 7 2021, 7:29 AM
kmclaughlin requested review of this revision.Jun 7 2021, 7:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2021, 7:29 AM
sdesmalen added inline comments.Jun 7 2021, 7:50 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
557

Can you add a doxygen description for the interface?

1309

Is this interface in the CostModel necessary? It seems the one in InnerLoopVectorizer sufficient?

llvm/test/Transforms/LoopVectorize/AArch64/strict-fadd.ll
652

Does this require a new combination, or could it reuse e.g. !2?

kmclaughlin marked an inline comment as done.
  • Added some comments describing useOrderedReductions
  • Reused an existing combination of hints for the @fast_induction_and_reduction test and updated the CHECK lines accordingly
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
1309

Hi @sdesmalen, I think the interface in the CostModel is necessary for other places where useOrderedReductions is called that aren't changed by this patch, e.g. LoopVectorizationCostModel::collectInLoopReductions()

sdesmalen accepted this revision.Jun 7 2021, 9:41 AM

Thanks @kmclaughlin, this looks like an important step towards being able to make EnableStrictReductions enabled by default in the future. This makes the behaviour compatible with the odd 'hint implies reordering' behaviour it had before, with or without the new -enable-strict-reductions flag.
So LGTM!

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
1309

Ah that makes sense, thanks!

This revision is now accepted and ready to land.Jun 7 2021, 9:41 AM
This revision was landed with ongoing or failed builds.Jun 8 2021, 2:40 AM
This revision was automatically updated to reflect the committed changes.