about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-08 07:18:17 +0000
committerbors <bors@rust-lang.org>2024-03-08 07:18:17 +0000
commit14fbc3c00525b41a3a3ee2c90e9ab6fd3b05274f (patch)
tree81cec2387610314e63c2468b5c3a2d1b797b6529 /compiler/rustc_codegen_llvm/src/llvm/ffi.rs
parent9fb91aa2e70bfcc1c0adaad79711f0321ea81ece (diff)
parent2884230df2bdf6ff23d51808f5e2f270dfbe0d3a (diff)
downloadrust-14fbc3c00525b41a3a3ee2c90e9ab6fd3b05274f.tar.gz
rust-14fbc3c00525b41a3a3ee2c90e9ab6fd3b05274f.zip
Auto merge of #120268 - DianQK:otherwise_is_last_variant_switchs, r=oli-obk
Replace the default branch with an unreachable branch If it is the last variant

Fixes #119520. Fixes #110097.

LLVM currently has limited ability to eliminate dead branches in switches, even with the patch of https://github.com/llvm/llvm-project/issues/73446.

The main reasons are as follows:

- Additional costs are required to calculate the range of values, and there exist many scenarios that cannot be analyzed accurately.
- Matching values by bitwise calculation cannot handle odd branches, nor can it handle values like `-1, 0, 1`. See [SimplifyCFG.cpp#L5424](https://github.com/llvm/llvm-project/blob/llvmorg-17.0.6/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L5424) and https://llvm.godbolt.org/z/qYMqhvMa8
- The current range information is continuous, even if the metadata for the range is submitted. See [ConstantRange.cpp#L1869-L1870](https://github.com/llvm/llvm-project/blob/llvmorg-17.0.6/llvm/lib/IR/ConstantRange.cpp#L1869-L1870).
- The metadata of the range may be lost in passes such as SROA. See https://rust.godbolt.org/z/e7f87vKMK.

Although we can make improvements, I think it would be more appropriate to put this issue to rustc first. After all, we can easily know the possible values.

Note that we've currently found a slow compilation problem in the presence of unreachable branches. See
https://github.com/llvm/llvm-project/issues/78578.

r? compiler
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm/ffi.rs')
0 files changed, 0 insertions, 0 deletions