[llvm] [InlineCost] Consider the default branch when calculating cost (PR #77856)

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 18:34:38 PDT 2024


DianQK wrote:

> Someone just reported to me internally that this caused a benchmark regression in our downstream.

I have created #81723 to track some regressions. I haven't started my research yet because this case is too big.
Can you provide a reproducible example? (It's okay if you can't.)

> I wonder if the default case was originally missing because it should just be a fallthrough after all the other cases are picked off. It shouldn't have any code. Given N destinations for a switch you only need N-1 compares and branches. Maybe an unreachable default should reduce the number of case clusters since one case cluster check wouldn't be needed? Though I'm not sure exactly what the backend generates.

I believe that we will create extra instructions if the default branch is reachable. See https://llvm.godbolt.org/z/x7azoP7eY.

```asm
bar1: # @bar1
  cmp rdi, 6
  ja .LBB0_6
  ...
```

This regression is likely coming from the select lookup vs compare instructions if I guess it right. See https://llvm.godbolt.org/z/cYdoef4cT.

I will prioritize the issue because it's becoming important. :) I'll report back my progress this weekend.

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


More information about the llvm-commits mailing list