[llvm] [AMDGPU] Add getCmpSelInstrCost override to re-enable SimplifyCFG speculation for vector types (PR #208043)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 09:39:25 PDT 2026


================
@@ -980,6 +983,51 @@ InstructionCost GCNTTIImpl::getCFInstrCost(unsigned Opcode,
   return BaseT::getCFInstrCost(Opcode, CostKind, I);
 }
 
+InstructionCost GCNTTIImpl::getCmpSelInstrCost(
+    unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
+    TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info,
+    TTI::OperandValueInfo Op2Info, const Instruction *I) const {
+  if (isa<ScalableVectorType>(ValTy))
+    return InstructionCost::getInvalid();
+
+  // For size and latency cost kinds, return a low cost independent of vector
+  // width to enable SimplifyCFG's speculativelyExecuteBB optimization.
+  if (CostKind != TTI::TCK_RecipThroughput)
+    return 1;
+
+  // Compute cost based on type legalization.
+  const TargetLoweringBase *TLI = getTLI();
+  if (TLI->getValueType(DL, ValTy, true) == MVT::Other)
+    return 1;
+
+  const int ISD = TLI->InstructionOpcodeToISD(Opcode);
+  assert(ISD && "Invalid opcode");
+  std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
+
+  if (!ValTy->isVectorTy())
+    return TLI->isOperationExpand(ISD, LT.second) ? 1 : LT.first;
+
+  if (!TLI->isOperationExpand(ISD, LT.second) && !LT.second.isVector()) {
+    // The operation is legal. Assume it costs 1. Multiply
+    // by the type-legalization overhead.
+    return LT.first * 1;
+  }
+
----------------
arsenm wrote:

This looks like a more confusing version of the default logic. This also doesn't account for vector selects remapping to VSELECT. Can you replace all of this by calling the base implementation? 

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


More information about the llvm-commits mailing list