about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-19 08:03:40 +0000
committerbors <bors@rust-lang.org>2025-07-19 08:03:40 +0000
commit83825dd277503edf5d7eda6be8b5fb9896f343f5 (patch)
tree5996e9be886f9b180004a171e19d7270026daa79 /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
parent1079c5edb2bd837e5c4cf8c7db2892db359a3862 (diff)
parent4fa23d96bc9334716b8f50511f5a920b46d349dd (diff)
downloadrust-83825dd277503edf5d7eda6be8b5fb9896f343f5.tar.gz
rust-83825dd277503edf5d7eda6be8b5fb9896f343f5.zip
Auto merge of #143784 - scottmcm:enums-again-new-ex2, r=dianqk
Simplify discriminant codegen for niche-encoded variants which don't wrap across an integer boundary

Inspired by rust-lang/rust#139729, this attempts to be a much-simpler and more-localized change while still making a difference.  (Specifically, this does not try to solve the problem with select-sinking, leaving that to be fixed by https://github.com/llvm/llvm-project/issues/134024 -- once it gets released -- instead of in rustc's codegen.)

What this *does* improve is checking for the variant in a 3+ variant enum when that variant is the type providing the niche.  Something like `if let Foo::WithBool(_) = ...` previously compiled to `ugt(add(x, -2), 2)`, which is non-trivial to think about because it's depending on the unsigned wrapping to shift the 0/1 up above 2.  With this PR it compiles to just `ult(x, 2)`, which is probably what you'd have written yourself if you were doing it by hand to look for "is this byte a bool?".

That's done by leaving most of the codegen alone, but adding a couple new special cases to the `is_niche` check.  The default looks at the relative discriminant, but in the common cases where there's no wraparound involved, we can just check the original value, rather than the offsetted one.

The first commit just adds some tests, so the best way to see the effect of this change is to look at the second commit and how it updates the test expectations.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions