Skip to content

Commit 3a8998b

Browse files
committed
Use BinOp::Cmp for iNN::signum
This way it can use the nice new LLVM intrinsic in LLVM20.
1 parent a18bd8a commit 3a8998b

5 files changed

+6
-6
lines changed

library/core/src/intrinsics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,8 @@ pub const fn bitreverse<T: Copy>(_x: T) -> T {
32423242
/// large and difficult to optimize.
32433243
///
32443244
/// The stabilized version of this intrinsic is [`Ord::cmp`].
3245+
#[rustc_intrinsic_const_stable_indirect]
3246+
#[rustc_nounwind]
32453247
#[rustc_intrinsic]
32463248
#[rustc_intrinsic_must_be_overridden]
32473249
pub const fn three_way_compare<T: Copy>(_lhs: T, _rhss: T) -> crate::cmp::Ordering {

library/core/src/num/int_macros.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3526,9 +3526,7 @@ macro_rules! int_impl {
35263526
// exactly like we need and can be the place to deal with the complexity.
35273527

35283528
// FIXME(const-hack): replace with cmp
3529-
if self < 0 { -1 }
3530-
else if self == 0 { 0 }
3531-
else { 1 }
3529+
crate::intrinsics::three_way_compare(self, 0) as Self
35323530
}
35333531

35343532
/// 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)