Skip to content

Commit 4b3f115

Browse files
committed
Remove an unneeded helper from the tuple library code
1 parent ec1393f commit 4b3f115

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

library/core/src/tuple.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,6 @@ macro_rules! maybe_tuple_doc {
161161
};
162162
}
163163

164-
#[inline]
165-
const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool {
166-
// FIXME: Just use `==` once that's const-stable on `Option`s.
167-
// This is mapping `None` to 2 and then doing the comparison afterwards
168-
// because it optimizes better (`None::<Ordering>` is represented as 2).
169-
x as i8
170-
== match c {
171-
Some(c) => c as i8,
172-
None => 2,
173-
}
174-
}
175-
176164
// Constructs an expression that performs a lexical ordering using method `$rel`.
177165
// The values are interleaved, so the macro invocation for
178166
// `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, opt_is_lt, a1, b1,
@@ -183,7 +171,7 @@ const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool {
183171
macro_rules! lexical_ord {
184172
($rel: ident, $ne_rel: ident, $a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {{
185173
let c = PartialOrd::partial_cmp(&$a, &$b);
186-
if !ordering_is_some(c, Equal) { ordering_is_some(c, $ne_rel) }
174+
if c != Some(Equal) { c == Some($ne_rel) }
187175
else { lexical_ord!($rel, $ne_rel, $($rest_a, $rest_b),+) }
188176
}};
189177
($rel: ident, $ne_rel: ident, $a:expr, $b:expr) => {

tests/codegen/comparison-operators-2-tuple.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ type TwoTuple = (i16, u16);
1010
//
1111
// The operators are all overridden directly, so should optimize easily.
1212
//
13-
// Yes, the `s[lg]t` is correct for the `[lg]e` version because it's only used
14-
// in the side of the select where we know the values are *not* equal.
13+
// slt-vs-sle and sgt-vs-sge don't matter because they're only used in the side
14+
// of the select where we know the values are not equal, and thus the tests
15+
// use a regex to allow either, since unimportant changes to the implementation
16+
// sometimes result in changing what LLVM decides to emit for this.
1517
//
1618

1719
// CHECK-LABEL: @check_lt_direct
1820
// CHECK-SAME: (i16 noundef %[[A0:.+]], i16 noundef %[[A1:.+]], i16 noundef %[[B0:.+]], i16 noundef %[[B1:.+]])
1921
#[no_mangle]
2022
pub fn check_lt_direct(a: TwoTuple, b: TwoTuple) -> bool {
2123
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
22-
// CHECK-DAG: %[[CMP0:.+]] = icmp slt i16 %[[A0]], %[[B0]]
24+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{slt|sle}} i16 %[[A0]], %[[B0]]
2325
// CHECK-DAG: %[[CMP1:.+]] = icmp ult i16 %[[A1]], %[[B1]]
2426
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
2527
// CHECK: ret i1 %[[R]]
@@ -31,7 +33,7 @@ pub fn check_lt_direct(a: TwoTuple, b: TwoTuple) -> bool {
3133
#[no_mangle]
3234
pub fn check_le_direct(a: TwoTuple, b: TwoTuple) -> bool {
3335
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
34-
// CHECK-DAG: %[[CMP0:.+]] = icmp slt i16 %[[A0]], %[[B0]]
36+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{slt|sle}} i16 %[[A0]], %[[B0]]
3537
// CHECK-DAG: %[[CMP1:.+]] = icmp ule i16 %[[A1]], %[[B1]]
3638
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
3739
// CHECK: ret i1 %[[R]]
@@ -43,7 +45,7 @@ pub fn check_le_direct(a: TwoTuple, b: TwoTuple) -> bool {
4345
#[no_mangle]
4446
pub fn check_gt_direct(a: TwoTuple, b: TwoTuple) -> bool {
4547
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
46-
// CHECK-DAG: %[[CMP0:.+]] = icmp sgt i16 %[[A0]], %[[B0]]
48+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{sgt|sge}} i16 %[[A0]], %[[B0]]
4749
// CHECK-DAG: %[[CMP1:.+]] = icmp ugt i16 %[[A1]], %[[B1]]
4850
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
4951
// CHECK: ret i1 %[[R]]
@@ -55,7 +57,7 @@ pub fn check_gt_direct(a: TwoTuple, b: TwoTuple) -> bool {
5557
#[no_mangle]
5658
pub fn check_ge_direct(a: TwoTuple, b: TwoTuple) -> bool {
5759
// CHECK-DAG: %[[EQ:.+]] = icmp eq i16 %[[A0]], %[[B0]]
58-
// CHECK-DAG: %[[CMP0:.+]] = icmp sgt i16 %[[A0]], %[[B0]]
60+
// CHECK-DAG: %[[CMP0:.+]] = icmp {{sgt|sge}} i16 %[[A0]], %[[B0]]
5961
// CHECK-DAG: %[[CMP1:.+]] = icmp uge i16 %[[A1]], %[[B1]]
6062
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[CMP1]], i1 %[[CMP0]]
6163
// CHECK: ret i1 %[[R]]

0 commit comments

Comments
 (0)