@@ -701,26 +701,21 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
701
701
702
702
void onFinalizeSwitch (unsigned JumpTableSize, unsigned NumCaseCluster,
703
703
bool DefaultDestUndefined) override {
704
+ if (!DefaultDestUndefined)
705
+ addCost (2 * InstrCost);
704
706
// If suitable for a jump table, consider the cost for the table size and
705
707
// branch to destination.
706
708
// Maximum valid cost increased in this function.
707
709
if (JumpTableSize) {
708
- // Suppose a default branch includes one compare and one conditional
709
- // branch if it's reachable.
710
- if (!DefaultDestUndefined)
711
- addCost (2 * InstrCost);
712
- // Suppose a jump table requires one load and one jump instruction.
713
710
int64_t JTCost =
714
- static_cast <int64_t >(JumpTableSize) * InstrCost + 2 * InstrCost;
711
+ static_cast <int64_t >(JumpTableSize) * InstrCost + 4 * InstrCost;
715
712
addCost (JTCost);
716
713
return ;
717
714
}
718
715
719
716
if (NumCaseCluster <= 3 ) {
720
717
// Suppose a comparison includes one compare and one conditional branch.
721
- // We can reduce a set of instructions if the default branch is
722
- // undefined.
723
- addCost ((NumCaseCluster - DefaultDestUndefined) * 2 * InstrCost);
718
+ addCost (NumCaseCluster * 2 * InstrCost);
724
719
return ;
725
720
}
726
721
@@ -1157,7 +1152,7 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
1157
1152
// FIXME: These constants are taken from the heuristic-based cost visitor.
1158
1153
// These should be removed entirely in a later revision to avoid reliance on
1159
1154
// heuristics in the ML inliner.
1160
- static constexpr int JTCostMultiplier = 2 ;
1155
+ static constexpr int JTCostMultiplier = 4 ;
1161
1156
static constexpr int CaseClusterCostMultiplier = 2 ;
1162
1157
static constexpr int SwitchDefaultDestCostMultiplier = 2 ;
1163
1158
static constexpr int SwitchCostMultiplier = 2 ;
@@ -1240,10 +1235,11 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
1240
1235
1241
1236
void onFinalizeSwitch (unsigned JumpTableSize, unsigned NumCaseCluster,
1242
1237
bool DefaultDestUndefined) override {
1238
+ if (!DefaultDestUndefined)
1239
+ increment (InlineCostFeatureIndex::switch_default_dest_penalty,
1240
+ SwitchDefaultDestCostMultiplier * InstrCost);
1241
+
1243
1242
if (JumpTableSize) {
1244
- if (!DefaultDestUndefined)
1245
- increment (InlineCostFeatureIndex::switch_default_dest_penalty,
1246
- SwitchDefaultDestCostMultiplier * InstrCost);
1247
1243
int64_t JTCost = static_cast <int64_t >(JumpTableSize) * InstrCost +
1248
1244
JTCostMultiplier * InstrCost;
1249
1245
increment (InlineCostFeatureIndex::jump_table_penalty, JTCost);
@@ -1252,8 +1248,7 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
1252
1248
1253
1249
if (NumCaseCluster <= 3 ) {
1254
1250
increment (InlineCostFeatureIndex::case_cluster_penalty,
1255
- (NumCaseCluster - DefaultDestUndefined) *
1256
- CaseClusterCostMultiplier * InstrCost);
1251
+ NumCaseCluster * CaseClusterCostMultiplier * InstrCost);
1257
1252
return ;
1258
1253
}
1259
1254
0 commit comments