Skip to content

Commit 5eb47ee

Browse files
committed
Add failing tests for some Option optimizations
1 parent bebcb9d commit 5eb47ee

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

tests/codegen/option-niche-eq.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ min-llvm-version: 20
12
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
23
#![crate_type = "lib"]
34

@@ -24,7 +25,7 @@ pub fn non_zero_signed_eq(l: Option<NonZero<i64>>, r: Option<NonZero<i64>>) -> b
2425
l == r
2526
}
2627

27-
// Test for #49892
28+
// FIXME(#49892)
2829
// This currently relies on a manual implementation of `PartialOrd`/`Ord` for `Option`
2930
// Once LLVM is better able to optimize this pattern, we can return to using a derive.
3031
// CHECK-LABEL: @non_zero_ord
@@ -73,13 +74,3 @@ pub fn niche_eq(l: Option<EnumWithNiche>, r: Option<EnumWithNiche>) -> bool {
7374
// CHECK-NEXT: ret i1
7475
l == r
7576
}
76-
77-
// FIXME: This should work too
78-
// // FIXME-CHECK-LABEL: @bool_eq
79-
// #[no_mangle]
80-
// pub fn bool_eq(l: Option<bool>, r: Option<bool>) -> bool {
81-
// // FIXME-CHECK: start:
82-
// // FIXME-CHECK-NEXT: icmp eq i8
83-
// // FIXME-CHECK-NEXT: ret i1
84-
// l == r
85-
// }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ should-fail
2+
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
3+
//! FIXME(#49892)
4+
//! Tests that LLVM does not fully optimize comparisons of `Option<bool>`.
5+
//! If this starts passing, it can be moved to `tests/codegen/option-niche-eq.rs`
6+
#![crate_type = "lib"]
7+
8+
// CHECK-LABEL: @bool_eq
9+
#[no_mangle]
10+
pub fn bool_eq(l: Option<bool>, r: Option<bool>) -> bool {
11+
// CHECK: start:
12+
// CHECK-NEXT: icmp eq i8
13+
// CHECK-NEXT: ret i1
14+
l == r
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ should-fail
2+
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
3+
//! FIXME(#49892)
4+
//! Test that the derived implementation of `PartialEq` for `Option` is not fully
5+
//! optimized by LLVM. If this starts passing, the test and manual impl should
6+
//! be removed.
7+
#![crate_type = "lib"]
8+
9+
use std::num::NonZero;
10+
11+
#[derive(Copy, Clone, PartialEq, Eq)]
12+
pub enum Option<T> {
13+
None,
14+
Some(T),
15+
}
16+
17+
// CHECK-LABEL: @non_zero_eq
18+
#[no_mangle]
19+
pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool {
20+
// CHECK: start:
21+
// CHECK-NEXT: icmp eq i32
22+
// CHECK-NEXT: ret i1
23+
l == r
24+
}

0 commit comments

Comments
 (0)