[llvm] [RISCV] Adjust select shuffle cost to reflect mask creation cost (PR #77963)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 14 23:03:40 PST 2024


================
@@ -443,10 +441,13 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
     // vsetivli     zero, 8, e8, mf2, ta, ma (ignored)
     // vmv.s.x      v0, a0
     // vmerge.vvm   v8, v9, v8, v0
+    // We use 2 for the cost of the mask materialization as this is the true
+    // cost for small masks and most shuffles are small.  At worst, this cost
+    // should be a very small constant for the constant pool load.  As such,
+    // we may bias towards large selects slightly more than truely warranted.
     return LT.first *
-           (TLI->getLMULCost(LT.second) + // FIXME: should be 1 for li
-            getRISCVInstructionCost({RISCV::VMV_S_X, RISCV::VMERGE_VVM},
-                                    LT.second, CostKind));
+           (2 + getRISCVInstructionCost({RISCV::VMERGE_VVM},
----------------
lukel97 wrote:

That makes sense. We would also need to address this FIXME in getRISCVInstructionCost too:
https://github.com/llvm/llvm-project/blob/e040252b545229041d0e51d397acd333936c5b42/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp#L87-L90

Probably needs to be done in a separate patch.

https://github.com/llvm/llvm-project/pull/77963


More information about the llvm-commits mailing list