[llvm] 0081ec1 - [VectorCombine] Add a mask for SK_Broadcast shuffle costing (#85808)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 08:57:12 PDT 2024


Author: Philip Reames
Date: 2024-03-19T08:57:09-07:00
New Revision: 0081ec11d86f34982ac5b1df4f53943a92d5223f

URL: https://github.com/llvm/llvm-project/commit/0081ec11d86f34982ac5b1df4f53943a92d5223f
DIFF: https://github.com/llvm/llvm-project/commit/0081ec11d86f34982ac5b1df4f53943a92d5223f.diff

LOG: [VectorCombine] Add a mask for SK_Broadcast shuffle costing (#85808)

This is part of a series of small patches to compute shuffle masks for
the couple of cases where we call getShuffleCost without one. My goal is
to add an invariant that all calls to getShuffleCost for fixed length
vectors have a mask.

Note that this code appears to be reachable with scalable vectors, and
thus we have to only pass a non-empty mask when the number of elements
is precisely known.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index dc669e314a0d9a..85c8d3996bba51 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -786,9 +786,12 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
   // intrinsic
   VectorType *VecTy = cast<VectorType>(VPI.getType());
   TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+  SmallVector<int> Mask;
+  if (auto *FVTy = dyn_cast<FixedVectorType>(VecTy))
+    Mask.resize(FVTy->getNumElements(), 0);
   InstructionCost SplatCost =
       TTI.getVectorInstrCost(Instruction::InsertElement, VecTy, CostKind, 0) +
-      TTI.getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy);
+      TTI.getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy, Mask);
 
   // Calculate the cost of the VP Intrinsic
   SmallVector<Type *, 4> Args;


        


More information about the llvm-commits mailing list