[llvm] 4a35655 - [RISCV][TTI] Factor out getVSlideCost helper [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 14:29:07 PDT 2023


Author: Philip Reames
Date: 2023-08-22T14:16:51-07:00
New Revision: 4a35655dac7d1b57f62c0b6d4a3d661b95b7e3a1

URL: https://github.com/llvm/llvm-project/commit/4a35655dac7d1b57f62c0b6d4a3d661b95b7e3a1
DIFF: https://github.com/llvm/llvm-project/commit/4a35655dac7d1b57f62c0b6d4a3d661b95b7e3a1.diff

LOG: [RISCV][TTI] Factor out getVSlideCost helper [nfc]

Reasonable implementations may differ in complexity cost, so doing some API prepwork to support tunables.  Note that this patch only covers the cases where we model the slide cost as linear.  A separate patch will propose changing our insert and extract costs from constant-in-lmul to linear-in-lmul.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
    llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 720b2a0d7d8cc1..0b116c1bea514d 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -277,6 +277,14 @@ InstructionCost RISCVTTIImpl::getVRGatherVICost(MVT VT) {
   return getLMULCost(VT);
 }
 
+/// Return the cost of a vslidedown.vi/vx or vslideup.vi/vx instruction
+/// for the type VT.  (This does not cover the vslide1up or vslide1down
+/// variants.)  Slides may be linear in the number of vregs implied by LMUL,
+/// or may track the vrgather.vv cost. It is implementation-dependent.
+InstructionCost RISCVTTIImpl::getVSlideCost(MVT VT) {
+  return getLMULCost(VT);
+}
+
 InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
                                              VectorType *Tp, ArrayRef<int> Mask,
                                              TTI::TargetCostKind CostKind,
@@ -397,12 +405,12 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
     // Example sequence:
     // vsetivli     zero, 4, e8, mf2, tu, ma (ignored)
     // vslidedown.vi  v8, v9, 2
-    return LT.first * getLMULCost(LT.second);
+    return LT.first * getVSlideCost(LT.second);
   case TTI::SK_InsertSubvector:
     // Example sequence:
     // vsetivli     zero, 4, e8, mf2, tu, ma (ignored)
     // vslideup.vi  v8, v9, 2
-    return LT.first * getLMULCost(LT.second);
+    return LT.first * getVSlideCost(LT.second);
   case TTI::SK_Select: {
     // Example sequence:
     // li           a0, 90
@@ -449,7 +457,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
     // vslidedown+vslideup.
     // TODO: Multiplying by LT.first implies this legalizes into multiple copies
     // of similar code, but I think we expand through memory.
-    return 2 * LT.first * getLMULCost(LT.second);
+    return 2 * LT.first * getVSlideCost(LT.second);
   case TTI::SK_Reverse: {
     // TODO: Cases to improve here:
     // * Illegal vector types

diff  --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
index 9873046034e190..8e86940d03a02d 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
@@ -125,6 +125,7 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
 
   InstructionCost getVRGatherVVCost(MVT VT);
   InstructionCost getVRGatherVICost(MVT VT);
+  InstructionCost getVSlideCost(MVT VT);
 
   InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp,
                                  ArrayRef<int> Mask,


        


More information about the llvm-commits mailing list