Skip to content

Commit a9c4f37

Browse files
authored
Unrolled build for rust-lang#137835
Rollup merge of rust-lang#137835 - scottmcm:signum, r=compiler-errors Use `BinOp::Cmp` for `iNN::signum` This way it can use the nice new LLVM intrinsic in LLVM20.
2 parents ed3a4aa + 8004615 commit a9c4f37

5 files changed

+10
-11
lines changed

library/core/src/intrinsics/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2628,13 +2628,15 @@ pub const fn bswap<T: Copy>(x: T) -> T;
26282628
#[rustc_intrinsic]
26292629
pub const fn bitreverse<T: Copy>(x: T) -> T;
26302630

2631-
/// Does a three-way comparison between the two integer arguments.
2631+
/// Does a three-way comparison between the two arguments,
2632+
/// which must be of character or integer (signed or unsigned) type.
26322633
///
2633-
/// This is included as an intrinsic as it's useful to let it be one thing
2634-
/// in MIR, rather than the multiple checks and switches that make its IR
2635-
/// large and difficult to optimize.
2634+
/// This was originally added because it greatly simplified the MIR in `cmp`
2635+
/// implementations, and then LLVM 20 added a backend intrinsic for it too.
26362636
///
26372637
/// The stabilized version of this intrinsic is [`Ord::cmp`].
2638+
#[rustc_intrinsic_const_stable_indirect]
2639+
#[rustc_nounwind]
26382640
#[rustc_intrinsic]
26392641
pub const fn three_way_compare<T: Copy>(lhs: T, rhss: T) -> crate::cmp::Ordering;
26402642

library/core/src/num/int_macros.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3571,10 +3571,7 @@ macro_rules! int_impl {
35713571
// so delegate it to `Ord` which is already producing -1/0/+1
35723572
// exactly like we need and can be the place to deal with the complexity.
35733573

3574-
// FIXME(const-hack): replace with cmp
3575-
if self < 0 { -1 }
3576-
else if self == 0 { 0 }
3577-
else { 1 }
3574+
crate::intrinsics::three_way_compare(self, 0) as Self
35783575
}
35793576

35803577
/// Returns `true` if `self` is positive and `false` if the number is zero or

tests/mir-opt/lower_intrinsics.three_way_compare_char.LowerIntrinsics.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
_4 = copy _1;
1919
StorageLive(_5);
2020
_5 = copy _2;
21-
- _3 = three_way_compare::<char>(move _4, move _5) -> [return: bb1, unwind continue];
21+
- _3 = three_way_compare::<char>(move _4, move _5) -> [return: bb1, unwind unreachable];
2222
+ _3 = Cmp(move _4, move _5);
2323
+ goto -> bb1;
2424
}

tests/mir-opt/lower_intrinsics.three_way_compare_signed.LowerIntrinsics.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
_4 = copy _1;
1616
StorageLive(_5);
1717
_5 = copy _2;
18-
- _3 = three_way_compare::<i16>(move _4, move _5) -> [return: bb1, unwind continue];
18+
- _3 = three_way_compare::<i16>(move _4, move _5) -> [return: bb1, unwind unreachable];
1919
+ _3 = Cmp(move _4, move _5);
2020
+ goto -> bb1;
2121
}

tests/mir-opt/lower_intrinsics.three_way_compare_unsigned.LowerIntrinsics.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
_4 = copy _1;
1919
StorageLive(_5);
2020
_5 = copy _2;
21-
- _3 = three_way_compare::<u32>(move _4, move _5) -> [return: bb1, unwind continue];
21+
- _3 = three_way_compare::<u32>(move _4, move _5) -> [return: bb1, unwind unreachable];
2222
+ _3 = Cmp(move _4, move _5);
2323
+ goto -> bb1;
2424
}

0 commit comments

Comments
 (0)