Skip to content

Commit ffc4e6d

Browse files
committed
[X86] Estimate the codesize cost of switch
1 parent 05a3f76 commit ffc4e6d

File tree

2 files changed

+428
-0
lines changed

2 files changed

+428
-0
lines changed

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6155,6 +6155,23 @@ X86TTIImpl::getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
61556155
InstructionCost X86TTIImpl::getCFInstrCost(unsigned Opcode,
61566156
TTI::TargetCostKind CostKind,
61576157
const Instruction *I) const {
6158+
if (Opcode == Instruction::Switch && CostKind == TTI::TCK_CodeSize) {
6159+
unsigned JumpTableSize, NumSuccs = I->getNumSuccessors();
6160+
getEstimatedNumberOfCaseClusters(*cast<SwitchInst>(I), JumpTableSize,
6161+
nullptr, nullptr);
6162+
// A trivial unconditional branch.
6163+
if (NumSuccs == 1)
6164+
return TTI::TCC_Basic;
6165+
6166+
// Assume that lowering the switch block is implemented by binary search if
6167+
// no jump table is generated.
6168+
if (JumpTableSize == 0)
6169+
return llvm::Log2_32_Ceil(NumSuccs) * 2 * TTI::TCC_Basic;
6170+
6171+
// Indirect branch + default compare + default jump
6172+
return 3 * TTI::TCC_Basic;
6173+
}
6174+
61586175
if (CostKind != TTI::TCK_RecipThroughput)
61596176
return Opcode == Instruction::PHI ? TTI::TCC_Free : TTI::TCC_Basic;
61606177
// Branches are assumed to be predicted.

0 commit comments

Comments
 (0)