diff options
| author | bors <bors@rust-lang.org> | 2025-02-18 07:49:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-18 07:49:09 +0000 |
| commit | 3b022d8ceea570db9730be34d964f0cc663a567f (patch) | |
| tree | 98b0584387859ce2ebcc221b9b86997cce17ba7b /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | aaa861493456e8a10e552dd208f85486de772007 (diff) | |
| parent | 7bb5f4dd78a7a45729ab503805ba1b3065cb0de9 (diff) | |
| download | rust-3b022d8ceea570db9730be34d964f0cc663a567f.tar.gz rust-3b022d8ceea570db9730be34d964f0cc663a567f.zip | |
Auto merge of #133852 - x17jiri:cold_path, r=saethlin
improve cold_path()
#120370 added a new instrinsic `cold_path()` and used it to fix `likely` and `unlikely`
However, in order to limit scope, the information about cold code paths is only used in 2-target switch instructions. This is sufficient for `likely` and `unlikely`, but limits usefulness of `cold_path` for idiomatic rust. For example, code like this:
```
if let Some(x) = y { ... }
```
may generate 3-target switch:
```
switch y.discriminator:
0 => true branch
1 = > false branch
_ => unreachable
```
and therefore marking a branch as cold will have no effect.
This PR improves `cold_path()` to work with arbitrary switch instructions.
Note that for 2-target switches, we can use `llvm.expect`, but for multiple targets we need to manually emit branch weights. I checked Clang and it also emits weights in this situation. The Clang's weight calculation is more complex that this PR, which I believe is mainly because `switch` in `C/C++` can have multiple cases going to the same target.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
