This is an archive of the discontinued LLVM Phabricator instance.

[CostModel] Use min/max intrinsics for vecreduce.min/max costs
ClosedPublic

Authored by dmgreen on Jun 22 2023, 7:02 AM.

Details

Summary

This changes the costmodelling of the vecreduce.min/max nodes to use the costs of the relevant min/max intrinsics instead of expanding them to compare and selects. The getMinMaxReductionCost have changed to take a Opcode for the relevant intrinsic, dropping the IsUnsigned and CondTy parameters as they are no longer needed.

A follow up patch will add some basic fminimum/fmaximum costmodelling.

Diff Detail

Event Timeline

dmgreen created this revision.Jun 22 2023, 7:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 7:02 AM
dmgreen requested review of this revision.Jun 22 2023, 7:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 7:02 AM
nikic added inline comments.Jun 22 2023, 7:08 AM
llvm/include/llvm/Analysis/TargetTransformInfo.h
1412

Opcode -> IntrinsicID? We don't usually use the term opcode for intrinsics. Could also use Intrinsic::ID type here (unless it's not available).

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
13807–13809

Use this value instead of your switch?

anna added a comment.Jun 22 2023, 1:38 PM

Not to hijack this patch, but I was experimenting a similar patch for Loop vectorizer when trip count of the loop is low (when we vectorize it, we get regressions since we do not consider out-of-loop reduction cost in LoopVectorizer). The plan is to add a TTIHook, I'll put the change up for review.

dmgreen updated this revision to Diff 533860.Jun 22 2023, 10:35 PM

Use Intrinsic::ID

Not to hijack this patch, but I was experimenting a similar patch for Loop vectorizer when trip count of the loop is low (when we vectorize it, we get regressions since we do not consider out-of-loop reduction cost in LoopVectorizer). The plan is to add a TTIHook, I'll put the change up for review.

Sounds good. Low trip count loops are often unrolled prior to vectorization (or they are large so the overheads are quite small in comparison). The loop vectorizer hasn't in the past modelled many of the loop invariant overheads such as reductions and setup splats or constants. In here and D153548 my main aim was just to get some basic AArch64 cost modelling for the intrinsics.

nikic accepted this revision.Jun 23 2023, 12:21 AM

LGTM

This revision is now accepted and ready to land.Jun 23 2023, 12:21 AM