[llvm] [InlineCost] Correct the default branch cost for the switch statement (PR #85160)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 07:04:46 PDT 2024
================
@@ -536,7 +536,13 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
// Considering comparisons from leaf and non-leaf nodes, we can estimate the
// number of comparisons in a simple closed form :
// n + n / 2 - 1 = n * 3 / 2 - 1
-int64_t getExpectedNumberOfCompare(int NumCaseCluster) {
+int64_t getExpectedNumberOfCompare(int NumCaseCluster,
+ bool DefaultDestUndefined) {
+ // The compare instruction count should be less than the branch count
+ // when default branch is undefined.
+ if (DefaultDestUndefined) {
+ return static_cast<int64_t>(NumCaseCluster) - 1;
+ }
----------------
dtcxzyw wrote:
```suggestion
if (DefaultDestUndefined)
return static_cast<int64_t>(NumCaseCluster) - 1;
```
Please drop the braces.
Is this heuristic correct?
https://github.com/llvm/llvm-project/pull/85160
More information about the llvm-commits
mailing list