This is an archive of the discontinued LLVM Phabricator instance.

[Cost] Add CostKind to getVectorInstrCost and its related users
ClosedPublic

Authored by arcbbb on Jan 19 2023, 7:38 AM.

Details

Summary

LoopUnroll estimates the loop size via getInstructionCost(),
but getInstructionCost() cannot pass CostKind to getVectorInstrCost().
And so does getShuffleCost() to getBroadcastShuffleOverhead(),
getPermuteShuffleOverhead(), getExtractSubvectorOverhead(),
and getInsertSubvectorOverhead().

To address this, this patch adds an argument CostKind to these
functions.

Diff Detail

Event Timeline

arcbbb created this revision.Jan 19 2023, 7:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 7:38 AM
arcbbb requested review of this revision.Jan 19 2023, 7:38 AM
arcbbb added inline comments.Jan 19 2023, 7:49 AM
llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-latency.ll
54

This is because of the change in

diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index 14f1f83b93ea..2293d6dfc5a3 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -4257,6 +4257,7 @@ X86TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
 }
 
 InstructionCost X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
+                                               TTI::TargetCostKind CostKind,
                                                unsigned Index, Value *Op0,
                                                Value *Op1) {
   static const CostTblEntry SLMCostTbl[] = {
@@ -4269,7 +4270,6 @@ InstructionCost X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
   assert(Val->isVectorTy() && "This must be a vector type");
   Type *ScalarType = Val->getScalarType();
   InstructionCost RegisterFileMoveCost = 0;
-  TTI::TargetCostKind CostKind = TTI::TargetCostKind::TCK_RecipThroughput;
 
   // Non-immediate extraction/insertion can be handled as a sequence of
   // aliased loads+stores via the stack.
craig.topper added inline comments.Jan 19 2023, 9:48 AM
llvm/include/llvm/CodeGen/BasicTTIImpl.h
1677

Mind labeling the true and false parameters while you're here? Should be the same as line 1441.

1732

Label and the true and false

1743

Label the true and false

2155

Label the true and false

Thanks for looking at this, TTI changes are always a slog :)

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

(trivial) Pull out the repeated uses of TTI::TCK_RecipThroughput into a common CostKind variable

arcbbb updated this revision to Diff 490884.Jan 20 2023, 8:49 AM
  • Updates
    1. Address Craig's and Simon's comments a. Labeling the true and false parameters b. Replace TTI::TCK_RecipThroughput with a common CostKind variable.
RKSimon accepted this revision.Jan 20 2023, 9:38 AM

LGTM - cheers

This revision is now accepted and ready to land.Jan 20 2023, 9:38 AM
This revision was landed with ongoing or failed builds.Jan 21 2023, 5:41 AM
This revision was automatically updated to reflect the committed changes.