rust/compiler/rustc_codegen_ssa/src
bors 83825dd277 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.
2025-07-19 08:03:40 +00:00
..
back Rollup merge of #143846 - usamoi:gc, r=bjorn3 2025-07-18 04:27:52 +02:00
debuginfo Flatten ifs in rustc_codegen_ssa 2025-03-17 18:56:52 +00:00
mir Auto merge of #143784 - scottmcm:enums-again-new-ex2, r=dianqk 2025-07-19 08:03:40 +00:00
traits Rollup merge of #143388 - bjorn3:lto_refactors, r=compiler-errors 2025-07-17 03:58:28 +02:00
assert_module_sources.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
base.rs Rollup merge of #143388 - bjorn3:lto_refactors, r=compiler-errors 2025-07-17 03:58:28 +02:00
codegen_attrs.rs use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
common.rs Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
errors.rs Port #[link_ordinal] to the new attribute parsing infrastructure. 2025-07-13 11:51:01 +02:00
lib.rs [Arm64EC] Only decorate functions with # 2025-06-23 12:38:35 -07:00
meth.rs Eliminate all direct uses of LLVMMDStringInContext2 2025-07-14 08:27:08 +00:00
mono_item.rs use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
size_of_val.rs Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
target_features.rs Rollup merge of #142876 - JonathanBrouwer:target_feature_parser, r=oli-obk 2025-07-03 13:29:36 +02:00