This is an archive of the discontinued LLVM Phabricator instance.

[SLP] Only use const args for intrinsic cost if all match.
Needs ReviewPublic

Authored by fhahn on Mar 28 2023, 1:00 PM.

Details

Summary

At the moment, the SLP vectorizer uses the arguments for the first
call in the bundle to the intrinsic cost estimate. This can lead to
mis-classifications, causing the SLP vectorizer to underestimate the
vector call cost.

The main case is constant arguments, where incorrectly assuming the same
contant is passed for all vector lanes can impact the cost computation.
An example where this estimate leads to sub-optimal code is fshl calls,
illustrated in the test case.

This patch updates SLP to more careful and not use arguments if
different constants are passed in different lanes.

This was exposed by 55c600819f92ed33bef868b5056b699915d645fa/D140392.

Diff Detail

Event Timeline

fhahn created this revision.Mar 28 2023, 1:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 1:00 PM
fhahn requested review of this revision.Mar 28 2023, 1:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 1:00 PM
ABataev added inline comments.Mar 28 2023, 1:07 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
6270

Unused var?

6271–6279

So, you're checking that all args have the same value here, right? Looks like this is very target-specific, not sure that it shall affect all targets. You need to adjust the cost of the Const vector, built for this case, not the cost of the vector call. Or pass arguments to CostAttrs and use them for the extra analysis in getIntrinsicInstrCost()