This is an archive of the discontinued LLVM Phabricator instance.

[LV] Cache call vectorization decisions
Needs ReviewPublic

Authored by huntergr on Jul 20 2023, 2:06 AM.

Details

Reviewers
fhahn
david-arm
Summary

LoopVectorize currently queries VFDatabase repeatedly for each CI, and each query to VFDatabase rescans all vector variants.

I think it would be better to find any available variants once for each VF and then cache that decision, similarly to how loads and stores are handled.

I've kept them in a separate map for this initial patch, but it may be worthwhile to unify the maps.

While doing this I had to move calls to collectInLoopReductions to ensure that the information was always available before making the decision, and discovered that a unit test for guarding the cost of strict fadd operations had been broken for a while -- the costs had been changed to those of a normal fmuladd intrinsic, not an in-order vector reduction, at least at the point the initial cost was calculated and displayed by LoopVectorize.

Diff Detail

Event Timeline

huntergr created this revision.Jul 20 2023, 2:06 AM
huntergr requested review of this revision.Jul 20 2023, 2:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 2:06 AM

Hi @huntergr this looks like a good clean up! I've not reviewed setVectorizedCallDecision, but I do have a few comments so far ...

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

Can you add comments here explaining what the function does?

1433

nit: This assert comment isn't quite right because isVector returns true for VF=vscale x 1. Same for the assert below.

3483

To avoid indenting so much code can you rewrite this as:

if (VF.isVector())
  return CallWideningDecisions.at(std::make_pair(CI, VF)).Cost;

... rest of unindented scalar code ...
6669

Why are these changes needed?

llvm/test/Transforms/LoopVectorize/AArch64/strict-fadd-cost.ll
9

Can this cost model fix be done in a separate patch so that it's not tied to the vector call changes? It also means this patch can become more like a NFC patch.