Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
215d8ed
combine rust files into one compilation
folkertdev Jul 11, 2025
426091a
update `Cargo.lock`
folkertdev Jul 19, 2025
83804bf
split rust code into crates
folkertdev Jul 11, 2025
3051039
generate arrays of type-erased function pointers
folkertdev Jul 11, 2025
b658b3d
work around not being able to project out of SIMD values any more
folkertdev Jul 22, 2025
4b95bb7
Merge pull request #1881 from folkertdev/s390x-project-simd
sayantn Jul 22, 2025
aaa5d91
remove `lazy_static` dependency from `intrinsic-test`
folkertdev Jul 22, 2025
4bf2151
Merge pull request #1880 from folkertdev/remove-lazy-static-dep
folkertdev Jul 22, 2025
cb27ff0
remove unused deps
klensy Jul 23, 2025
d8bf6c4
bump serde_with. Weird that it works without std feature, but
klensy Jul 23, 2025
75fc5ce
Merge pull request #1882 from klensy/deps
folkertdev Jul 23, 2025
a343926
Prepare for merging from rust-lang/rust
Kobzol Jul 23, 2025
67f73c7
Merge ref '5a30e4307f05' from rust-lang/rust
Kobzol Jul 23, 2025
8f0ffa8
Reformat code
Kobzol Jul 23, 2025
0231fa9
Merge pull request #1883 from Kobzol/pull
folkertdev Jul 23, 2025
be947d4
Add non-temporal note for maskmoveu_si128
197g Jul 24, 2025
14febfa
Merge pull request #1885 from 197g/maskmove-is-non-temporal
sayantn Jul 24, 2025
49ea48d
loongarch: Use unified data types for SIMD intrinsics
heiher Jul 19, 2025
cc15f02
Merge pull request #1879 from heiher/loong-simd-unified-types
folkertdev Jul 25, 2025
f998575
Merge pull request #1863 from folkertdev/combine-rust-files
sayantn Jul 25, 2025
90d97f6
feat: updated Argument<T> type for functional compatibility with other
madhav-madhusoodanan Jul 27, 2025
213fd4e
Merge pull request #1887 from madhav-madhusoodanan/intrinsic-test-arg…
folkertdev Jul 27, 2025
c07f8bb
chore: handling the case where --generate-only flag is passed
madhav-madhusoodanan Jul 27, 2025
15373cc
Merge pull request #1888 from madhav-madhusoodanan/intrinsic-test-gen…
folkertdev Jul 27, 2025
e6c0136
Use GitHub app for authenticating sync workflows
Kobzol Jul 29, 2025
d6c33bf
Merge pull request #1891 from Kobzol/ci-gh-app
tgross35 Jul 29, 2025
8926d9c
Prepare for merging from rust-lang/rust
invalid-email-address Jul 31, 2025
49aa0ec
Merge ref '32e7a4b92b10' from rust-lang/rust
invalid-email-address Jul 31, 2025
f95edbe
move gcc config parsing to parse_inner
Shourya742 Jul 30, 2025
3f9bf57
move dist to parse_inner
Shourya742 Jul 30, 2025
924912c
move target parsing to parse_inner
Shourya742 Jul 30, 2025
89219ff
move install to parse_inner
Shourya742 Jul 30, 2025
3248ff1
move llvm parsing to parse_inner
Shourya742 Jul 30, 2025
ddd2a54
move rust config to parse_inner
Shourya742 Jul 30, 2025
ae05591
Force initializing ExecutionContext with verbosity and fail_fast mode
Shourya742 Jul 30, 2025
82756fd
Extract TOML config loading and src directory computation into separa…
Shourya742 Jul 30, 2025
f89ea08
Split TOML postprocessing into a separate function
Shourya742 Jul 30, 2025
cfc40de
Override some build TOML values by flags
Shourya742 Jul 30, 2025
8652d96
Fix logging of config skip values
Shourya742 Jul 30, 2025
58a38cd
Fix verbosity setting
Shourya742 Jul 30, 2025
222dfcc
add install default implementation
Shourya742 Aug 1, 2025
bbe7c08
add gcc and dist default implementation
Shourya742 Aug 1, 2025
38ddefa
add llvm default implementation
Shourya742 Aug 1, 2025
8b80cb0
add rust default implementation
Shourya742 Aug 1, 2025
d3d3b10
make llvm toml fields follow a specific naming convention
Shourya742 Aug 1, 2025
c008a4b
make gcc toml fields follow a specific naming convention
Shourya742 Aug 1, 2025
4d2a2c2
make dist toml fields follow a specific naming convention
Shourya742 Aug 1, 2025
ad98550
make install toml fields follow a specific naming convention
Shourya742 Aug 1, 2025
2c96132
make build toml fields follow a specific naming convention
Shourya742 Aug 1, 2025
a75326b
move build config to the top of parse method
Shourya742 Aug 1, 2025
39d9cf7
move install config to the top of parse method
Shourya742 Aug 1, 2025
120d93e
move rust config to the top of parse method
Shourya742 Aug 1, 2025
f74f1a0
move llvm config to the top of parse method
Shourya742 Aug 1, 2025
7f20ad8
move dist and gcc config to the top of parse method
Shourya742 Aug 1, 2025
c861fbd
use gcc 15 as the linker on loongarch
folkertdev Aug 2, 2025
56ba98c
Merge pull request #1893 from folkertdev/loongarch-gcc
sayantn Aug 3, 2025
3b216c3
feat: Added another variant of the Constraint enum
madhav-madhusoodanan Aug 2, 2025
daa742a
Merge pull request #1892 from madhav-madhusoodanan/intrinsic-test-con…
folkertdev Aug 3, 2025
c691374
Merge pull request #1889 from rust-lang/rustc-pull
folkertdev Aug 3, 2025
d857d54
Print CGU reuse statistics when `-Zprint-mono-items` is enabled
Kobzol Aug 4, 2025
75e20af
Add new `test::print_merged_doctests_times` used by rustdoc to displa…
GuillaumeGomez Aug 4, 2025
36383dd
[win][arm64ec] Fix msvc-wholearchive for Arm64EC
dpaoliello Aug 5, 2025
76dce27
feat: cleaned the IntrinsicType struct and associated functions.
madhav-madhusoodanan Aug 5, 2025
e84116d
chore: moved chunk_info to `common` and code cleanup
madhav-madhusoodanan Aug 5, 2025
841c8e4
Merge pull request #1895 from madhav-madhusoodanan/intrinsic-test-int…
folkertdev Aug 5, 2025
de01bd3
use `IntoIterator` for the `add_flags` methods
folkertdev Aug 5, 2025
92f195c
Merge pull request #1896 from folkertdev/add-flags-into-iter
sayantn Aug 5, 2025
62c92f3
moved 35 tests to organized locations
Kivooeo Jul 24, 2025
b6e13e3
comments
Kivooeo Jul 24, 2025
962836d
remove redundant _toml suffix and other misc changes
Shourya742 Aug 4, 2025
81ed042
coverage: Remove all unstable support for MC/DC instrumentation
Zalathar Aug 6, 2025
c396521
[codegen] assume the tag, not the relative discriminant
scottmcm Aug 1, 2025
4ff22dd
Move some TypeVisitable/TypeFoldable impls to rustc_type_ir
flodiebold Nov 10, 2024
025fbe8
Add support for shortening `Instance` and use it
estebank Jul 29, 2025
1c428ec
move `type_check` out of `compute_regions`
lcnr Aug 7, 2025
d6dc363
add multiple known-bugs for NLL problem case 3
lqd Aug 7, 2025
e3aae61
add filtering lending iterator known-bug
lqd Aug 7, 2025
202963f
add multiple known-bugs for the linked-list cursor-like pattern of 46…
lqd Aug 7, 2025
6c02653
Prevent name collisions with internal implementation details
bjorn3 Aug 7, 2025
487e5ce
Introduce, implement and use CmResolver.
LorrensP-2158466 Aug 4, 2025
186cef0
Move metadata symbol export from exported_non_generic_symbols to expo…
bjorn3 Aug 7, 2025
29799c2
Add a missing UpcastFrom impl in rustc_type_ir
flodiebold Nov 10, 2024
34e5820
Clean up some resolved test regressions of const trait removals in std
ShoyuVanilla Aug 7, 2025
7ea5e79
Readd myself to review queue
jackh726 Aug 7, 2025
1c41c3d
Add minimal `armv7a-vex-v5` support
lewisfm Aug 7, 2025
8a87857
Add test.
cjgillot Aug 7, 2025
ebd60b9
Do not flatten derefs with ProjectionElem::Index.
cjgillot Aug 7, 2025
cb271d0
Rollup merge of #144400 - Kivooeo:issue3, r=jieyouxu
Zalathar Aug 8, 2025
44ffe10
Rollup merge of #144764 - scottmcm:tweak-impossible-discriminant-assu…
Zalathar Aug 8, 2025
af33da3
Rollup merge of #144807 - Shourya742:2025-07-30-streamline-config, r=…
Zalathar Aug 8, 2025
2b7659c
Rollup merge of #144899 - Kobzol:cgu-reuse, r=saethlin
Zalathar Aug 8, 2025
3f94101
Rollup merge of #144909 - GuillaumeGomez:extend-libtest-for-merged-do…
Zalathar Aug 8, 2025
ecce94c
Rollup merge of #144912 - LorrensP-2158466:smart-resolver, r=petroche…
Zalathar Aug 8, 2025
bdb082b
Rollup merge of #144914 - estebank:short-paths-2, r=fee1-dead
Zalathar Aug 8, 2025
2edfd36
Rollup merge of #144931 - dpaoliello:msvc-wholearchive, r=jieyouxu
Zalathar Aug 8, 2025
562222b
Rollup merge of #144999 - Zalathar:remove-mcdc, r=oli-obk
Zalathar Aug 8, 2025
0d22b2e
Rollup merge of #145009 - jackh726:ra-next-solver-changes, r=compiler…
Zalathar Aug 8, 2025
162e2e4
Rollup merge of #145030 - cjgillot:gvn-no-flatten-index, r=saethlin
Zalathar Aug 8, 2025
6f2d55b
Rollup merge of #145042 - heiher:stdarch-push, r=folkertdev
Zalathar Aug 8, 2025
e4b2fad
Rollup merge of #145047 - lcnr:yeet-mir-typeck, r=lqd
Zalathar Aug 8, 2025
432a4f2
Rollup merge of #145051 - bjorn3:prevent_linkage_symbol_name_collisio…
Zalathar Aug 8, 2025
ab0b90f
Rollup merge of #145053 - lqd:known-bugs, r=jackh726
Zalathar Aug 8, 2025
18f5e9b
Rollup merge of #145055 - bjorn3:move_metadata_symbol_export, r=saethlin
Zalathar Aug 8, 2025
bd7af8a
Rollup merge of #145057 - ShoyuVanilla:const-trait-tests-cleanup, r=p…
Zalathar Aug 8, 2025
9f0a7fe
Rollup merge of #145068 - jackh726:add-review, r=jackh726
Zalathar Aug 8, 2025
f6283ae
Rollup merge of #145070 - vexide:minimal-armv7a-vex-v5, r=wesleywiser
Zalathar Aug 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[codegen] assume the tag, not the relative discriminant
  • Loading branch information
scottmcm committed Aug 6, 2025
commit c396521fd38228945baf3437acdb27bf00d14919
43 changes: 29 additions & 14 deletions compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,35 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
bx.cx().const_uint(cast_to, niche_variants.start().as_u32() as u64);
(is_niche, tagged_discr, 0)
} else {
// Thanks to parameter attributes and load metadata, LLVM already knows
// the general valid range of the tag. It's possible, though, for there
// to be an impossible value *in the middle*, which those ranges don't
// communicate, so it's worth an `assume` to let the optimizer know.
// Most importantly, this means when optimizing a variant test like
// `SELECT(is_niche, complex, CONST) == CONST` it's ok to simplify that
// to `!is_niche` because the `complex` part can't possibly match.
//
// This was previously asserted on `tagged_discr` below, where the
// impossible value is more obvious, but that caused an intermediate
// value to become multi-use and thus not optimize, so instead this
// assumes on the original input which is always multi-use. See
// <https://github.com/llvm/llvm-project/issues/134024#issuecomment-3131782555>
//
// FIXME: If we ever get range assume operand bundles in LLVM (so we
// don't need the `icmp`s in the instruction stream any more), it
// might be worth moving this back to being on the switch argument
// where it's more obviously applicable.
if niche_variants.contains(&untagged_variant)
&& bx.cx().sess().opts.optimize != OptLevel::No
{
let impossible = niche_start
.wrapping_add(u128::from(untagged_variant.as_u32()))
.wrapping_sub(u128::from(niche_variants.start().as_u32()));
let impossible = bx.cx().const_uint_big(tag_llty, impossible);
let ne = bx.icmp(IntPredicate::IntNE, tag, impossible);
bx.assume(ne);
}

// With multiple niched variants we'll have to actually compute
// the variant index from the stored tag.
//
Expand Down Expand Up @@ -588,20 +617,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
let untagged_variant_const =
bx.cx().const_uint(cast_to, u64::from(untagged_variant.as_u32()));

// Thanks to parameter attributes and load metadata, LLVM already knows
// the general valid range of the tag. It's possible, though, for there
// to be an impossible value *in the middle*, which those ranges don't
// communicate, so it's worth an `assume` to let the optimizer know.
// Most importantly, this means when optimizing a variant test like
// `SELECT(is_niche, complex, CONST) == CONST` it's ok to simplify that
// to `!is_niche` because the `complex` part can't possibly match.
if niche_variants.contains(&untagged_variant)
&& bx.cx().sess().opts.optimize != OptLevel::No
{
let ne = bx.icmp(IntPredicate::IntNE, tagged_discr, untagged_variant_const);
bx.assume(ne);
}

let discr = bx.select(is_niche, tagged_discr, untagged_variant_const);

// In principle we could insert assumes on the possible range of `discr`, but
Expand Down
73 changes: 43 additions & 30 deletions tests/codegen-llvm/enum/enum-discriminant-eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,23 @@ pub enum Mid<T> {
pub fn mid_bool_eq_discr(a: Mid<bool>, b: Mid<bool>) -> bool {
// CHECK-LABEL: @mid_bool_eq_discr(

// CHECK: %[[A_REL_DISCR:.+]] = add nsw i8 %a, -2
// CHECK: %[[A_IS_NICHE:.+]] = icmp samesign ugt i8 %a, 1
// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i8 %[[A_REL_DISCR]], 1
// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i8 %a, 3
// CHECK: tail call void @llvm.assume(i1 %[[A_NOT_HOLE]])
// CHECK: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %[[A_REL_DISCR]], i8 1
// LLVM20: %[[A_REL_DISCR:.+]] = add nsw i8 %a, -2
// CHECK: %[[A_IS_NICHE:.+]] = icmp samesign ugt i8 %a, 1
// LLVM20: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %[[A_REL_DISCR]], i8 1

// CHECK: %[[B_REL_DISCR:.+]] = add nsw i8 %b, -2
// CHECK: %[[B_IS_NICHE:.+]] = icmp samesign ugt i8 %b, 1
// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i8 %[[B_REL_DISCR]], 1
// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i8 %b, 3
// CHECK: tail call void @llvm.assume(i1 %[[B_NOT_HOLE]])
// CHECK: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %[[B_REL_DISCR]], i8 1
// LLVM20: %[[B_REL_DISCR:.+]] = add nsw i8 %b, -2
// CHECK: %[[B_IS_NICHE:.+]] = icmp samesign ugt i8 %b, 1
// LLVM20: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %[[B_REL_DISCR]], i8 1

// LLVM21: %[[A_MOD_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %a, i8 3
// LLVM21: %[[B_MOD_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %b, i8 3

// LLVM20: %[[R:.+]] = icmp eq i8 %[[A_DISCR]], %[[B_DISCR]]
// LLVM21: %[[R:.+]] = icmp eq i8 %[[A_MOD_DISCR]], %[[B_MOD_DISCR]]
// CHECK: ret i1 %[[R]]
discriminant_value(&a) == discriminant_value(&b)
}
Expand All @@ -111,19 +116,23 @@ pub fn mid_bool_eq_discr(a: Mid<bool>, b: Mid<bool>) -> bool {
pub fn mid_ord_eq_discr(a: Mid<Ordering>, b: Mid<Ordering>) -> bool {
// CHECK-LABEL: @mid_ord_eq_discr(

// CHECK: %[[A_REL_DISCR:.+]] = add nsw i8 %a, -2
// CHECK: %[[A_IS_NICHE:.+]] = icmp sgt i8 %a, 1
// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i8 %[[A_REL_DISCR]], 1
// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i8 %a, 3
// CHECK: tail call void @llvm.assume(i1 %[[A_NOT_HOLE]])
// CHECK: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %[[A_REL_DISCR]], i8 1
// LLVM20: %[[A_REL_DISCR:.+]] = add nsw i8 %a, -2
// CHECK: %[[A_IS_NICHE:.+]] = icmp sgt i8 %a, 1
// LLVM20: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %[[A_REL_DISCR]], i8 1

// CHECK: %[[B_REL_DISCR:.+]] = add nsw i8 %b, -2
// CHECK: %[[B_IS_NICHE:.+]] = icmp sgt i8 %b, 1
// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i8 %[[B_REL_DISCR]], 1
// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i8 %b, 3
// CHECK: tail call void @llvm.assume(i1 %[[B_NOT_HOLE]])
// CHECK: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %[[B_REL_DISCR]], i8 1
// LLVM20: %[[B_REL_DISCR:.+]] = add nsw i8 %b, -2
// CHECK: %[[B_IS_NICHE:.+]] = icmp sgt i8 %b, 1
// LLVM20: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %[[B_REL_DISCR]], i8 1

// CHECK: %[[R:.+]] = icmp eq i8 %[[A_DISCR]], %[[B_DISCR]]
// LLVM21: %[[A_MOD_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %a, i8 3
// LLVM21: %[[B_MOD_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %b, i8 3

// LLVM20: %[[R:.+]] = icmp eq i8 %[[A_DISCR]], %[[B_DISCR]]
// LLVM21: %[[R:.+]] = icmp eq i8 %[[A_MOD_DISCR]], %[[B_MOD_DISCR]]
// CHECK: ret i1 %[[R]]
discriminant_value(&a) == discriminant_value(&b)
}
Expand All @@ -140,16 +149,16 @@ pub fn mid_nz32_eq_discr(a: Mid<NonZero<u32>>, b: Mid<NonZero<u32>>) -> bool {
pub fn mid_ac_eq_discr(a: Mid<AC>, b: Mid<AC>) -> bool {
// CHECK-LABEL: @mid_ac_eq_discr(

// LLVM20: %[[A_REL_DISCR:.+]] = xor i8 %a, -128
// CHECK: %[[A_IS_NICHE:.+]] = icmp slt i8 %a, 0
// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i8 %a, -127
// CHECK: tail call void @llvm.assume(i1 %[[A_NOT_HOLE]])
// LLVM20: %[[A_REL_DISCR:.+]] = xor i8 %a, -128
// CHECK: %[[A_IS_NICHE:.+]] = icmp slt i8 %a, 0
// LLVM20: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %[[A_REL_DISCR]], i8 1

// LLVM20: %[[B_REL_DISCR:.+]] = xor i8 %b, -128
// CHECK: %[[B_IS_NICHE:.+]] = icmp slt i8 %b, 0
// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i8 %b, -127
// CHECK: tail call void @llvm.assume(i1 %[[B_NOT_HOLE]])
// LLVM20: %[[B_REL_DISCR:.+]] = xor i8 %b, -128
// CHECK: %[[B_IS_NICHE:.+]] = icmp slt i8 %b, 0
// LLVM20: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i8 %[[B_REL_DISCR]], i8 1

// LLVM21: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i8 %a, i8 -127
Expand All @@ -166,21 +175,25 @@ pub fn mid_ac_eq_discr(a: Mid<AC>, b: Mid<AC>) -> bool {
pub fn mid_giant_eq_discr(a: Mid<Giant>, b: Mid<Giant>) -> bool {
// CHECK-LABEL: @mid_giant_eq_discr(

// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i128 %a, 6
// CHECK: tail call void @llvm.assume(i1 %[[A_NOT_HOLE]])
// CHECK: %[[A_TRUNC:.+]] = trunc nuw nsw i128 %a to i64
// CHECK: %[[A_REL_DISCR:.+]] = add nsw i64 %[[A_TRUNC]], -5
// LLVM20: %[[A_REL_DISCR:.+]] = add nsw i64 %[[A_TRUNC]], -5
// CHECK: %[[A_IS_NICHE:.+]] = icmp samesign ugt i128 %a, 4
// CHECK: %[[A_NOT_HOLE:.+]] = icmp ne i64 %[[A_REL_DISCR]], 1
// CHECK: tail call void @llvm.assume(i1 %[[A_NOT_HOLE]])
// CHECK: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i64 %[[A_REL_DISCR]], i64 1
// LLVM20: %[[A_DISCR:.+]] = select i1 %[[A_IS_NICHE]], i64 %[[A_REL_DISCR]], i64 1

// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i128 %b, 6
// CHECK: tail call void @llvm.assume(i1 %[[B_NOT_HOLE]])
// CHECK: %[[B_TRUNC:.+]] = trunc nuw nsw i128 %b to i64
// CHECK: %[[B_REL_DISCR:.+]] = add nsw i64 %[[B_TRUNC]], -5
// LLVM20: %[[B_REL_DISCR:.+]] = add nsw i64 %[[B_TRUNC]], -5
// CHECK: %[[B_IS_NICHE:.+]] = icmp samesign ugt i128 %b, 4
// CHECK: %[[B_NOT_HOLE:.+]] = icmp ne i64 %[[B_REL_DISCR]], 1
// CHECK: tail call void @llvm.assume(i1 %[[B_NOT_HOLE]])
// CHECK: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i64 %[[B_REL_DISCR]], i64 1
// LLVM20: %[[B_DISCR:.+]] = select i1 %[[B_IS_NICHE]], i64 %[[B_REL_DISCR]], i64 1

// LLVM21: %[[A_MODIFIED_TAG:.+]] = select i1 %[[A_IS_NICHE]], i64 %[[A_TRUNC]], i64 6
// LLVM21: %[[B_MODIFIED_TAG:.+]] = select i1 %[[B_IS_NICHE]], i64 %[[B_TRUNC]], i64 6
// LLVM21: %[[R:.+]] = icmp eq i64 %[[A_MODIFIED_TAG]], %[[B_MODIFIED_TAG]]

// CHECK: %[[R:.+]] = icmp eq i64 %[[A_DISCR]], %[[B_DISCR]]
// LLVM20: %[[R:.+]] = icmp eq i64 %[[A_DISCR]], %[[B_DISCR]]
// CHECK: ret i1 %[[R]]
discriminant_value(&a) == discriminant_value(&b)
}
Expand Down
24 changes: 12 additions & 12 deletions tests/codegen-llvm/enum/enum-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ pub fn match3(e: Option<&u8>) -> i16 {

#[derive(PartialEq)]
pub enum MiddleNiche {
A,
B,
C(bool),
D,
E,
A, // tag 2
B, // tag 3
C(bool), // untagged
D, // tag 5
E, // tag 6
}

// CHECK-LABEL: define{{( dso_local)?}} noundef{{( range\(i8 -?[0-9]+, -?[0-9]+\))?}} i8 @match4(i8{{.+}}%0)
// CHECK-NEXT: start:
// CHECK-NEXT: %[[REL_VAR:.+]] = add{{( nsw)?}} i8 %0, -2
// CHECK-NEXT: %[[NOT_IMPOSSIBLE:.+]] = icmp ne i8 %[[REL_VAR]], 2
// CHECK-NEXT: %[[NOT_IMPOSSIBLE:.+]] = icmp ne i8 %0, 4
// CHECK-NEXT: call void @llvm.assume(i1 %[[NOT_IMPOSSIBLE]])
// CHECK-NEXT: %[[REL_VAR:.+]] = add{{( nsw)?}} i8 %0, -2
// CHECK-NEXT: %[[NOT_NICHE:.+]] = icmp{{( samesign)?}} ult i8 %0, 2
// CHECK-NEXT: %[[DISCR:.+]] = select i1 %[[NOT_NICHE]], i8 2, i8 %[[REL_VAR]]
// CHECK-NEXT: switch i8 %[[DISCR]]
Expand Down Expand Up @@ -443,19 +443,19 @@ pub enum HugeVariantIndex {
V255(Never),
V256(Never),

Possible257,
Bool258(bool),
Possible259,
Possible257, // tag 2
Bool258(bool), // untagged
Possible259, // tag 4
}

// CHECK-LABEL: define{{( dso_local)?}} noundef{{( range\(i8 [0-9]+, [0-9]+\))?}} i8 @match5(i8{{.+}}%0)
// CHECK-NEXT: start:
// CHECK-NEXT: %[[NOT_IMPOSSIBLE:.+]] = icmp ne i8 %0, 3
// CHECK-NEXT: call void @llvm.assume(i1 %[[NOT_IMPOSSIBLE]])
// CHECK-NEXT: %[[REL_VAR:.+]] = add{{( nsw)?}} i8 %0, -2
// CHECK-NEXT: %[[REL_VAR_WIDE:.+]] = zext i8 %[[REL_VAR]] to i64
// CHECK-NEXT: %[[IS_NICHE:.+]] = icmp{{( samesign)?}} ugt i8 %0, 1
// CHECK-NEXT: %[[NICHE_DISCR:.+]] = add nuw nsw i64 %[[REL_VAR_WIDE]], 257
// CHECK-NEXT: %[[NOT_IMPOSSIBLE:.+]] = icmp ne i64 %[[NICHE_DISCR]], 258
// CHECK-NEXT: call void @llvm.assume(i1 %[[NOT_IMPOSSIBLE]])
// CHECK-NEXT: %[[DISCR:.+]] = select i1 %[[IS_NICHE]], i64 %[[NICHE_DISCR]], i64 258
// CHECK-NEXT: switch i64 %[[DISCR]],
// CHECK-NEXT: i64 257,
Expand Down
Loading