@@ -536,8 +536,16 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
536
536
// Considering comparisons from leaf and non-leaf nodes, we can estimate the
537
537
// number of comparisons in a simple closed form :
538
538
// n + n / 2 - 1 = n * 3 / 2 - 1
539
- int64_t getExpectedNumberOfCompare (int NumCaseCluster) {
540
- return 3 * static_cast <int64_t >(NumCaseCluster) / 2 - 1 ;
539
+ int64_t getExpectedNumberOfCompare (int NumCaseCluster,
540
+ bool DefaultDestUndefined) {
541
+ int64_t ExpectedNumber = 3 * static_cast <int64_t >(NumCaseCluster) / 2 - 1 ;
542
+ // FIXME: The compare instruction count should be less than the branch count
543
+ // when default branch is undefined. But this will cause some performance
544
+ // regressions. At least, we can now try to remove a compare instruction.
545
+ if (DefaultDestUndefined) {
546
+ ExpectedNumber -= 1 ;
547
+ }
548
+ return ExpectedNumber;
541
549
}
542
550
543
551
// / FIXME: if it is necessary to derive from InlineCostCallAnalyzer, note
@@ -724,9 +732,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
724
732
return ;
725
733
}
726
734
727
- // FIXME: Consider the case when default branch is undefined.
728
735
int64_t ExpectedNumberOfCompare =
729
- getExpectedNumberOfCompare (NumCaseCluster);
736
+ getExpectedNumberOfCompare (NumCaseCluster, DefaultDestUndefined );
730
737
int64_t SwitchCost = ExpectedNumberOfCompare * 2 * InstrCost;
731
738
732
739
addCost (SwitchCost);
@@ -1258,9 +1265,8 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
1258
1265
return ;
1259
1266
}
1260
1267
1261
- // FIXME: Consider the case when default branch is undefined.
1262
1268
int64_t ExpectedNumberOfCompare =
1263
- getExpectedNumberOfCompare (NumCaseCluster);
1269
+ getExpectedNumberOfCompare (NumCaseCluster, DefaultDestUndefined );
1264
1270
1265
1271
int64_t SwitchCost =
1266
1272
ExpectedNumberOfCompare * SwitchCostMultiplier * InstrCost;
0 commit comments