forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#137197 - scottmcm:cmp-20, r=ibraheemdev Update some comparison codegen tests now that they pass in LLVM20 Fixes rust-lang#106107 Needed one tweak to the default `PartialOrd::le` to get the test to pass. Everything but the derived 2-field `le` test passes even without the change to the defaults in the trait.
- Loading branch information
Showing
3 changed files
with
82 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//@ compile-flags: -C opt-level=1 | ||
//@ min-llvm-version: 20 | ||
|
||
// The `derive(PartialOrd)` for a 2-field type doesn't override `lt`/`le`/`gt`/`ge`. | ||
// This double-checks that the `Option<Ordering>` intermediate values used | ||
// in the operators for such a type all optimize away. | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::cmp::Ordering; | ||
|
||
#[derive(PartialOrd, PartialEq)] | ||
pub struct Foo(i32, u32); | ||
|
||
// CHECK-LABEL: @check_lt( | ||
// CHECK-SAME: i32{{.+}}%[[A0:.+]], i32{{.+}}%[[A1:.+]], i32{{.+}}%[[B0:.+]], i32{{.+}}%[[B1:.+]]) | ||
#[no_mangle] | ||
pub fn check_lt(a: Foo, b: Foo) -> bool { | ||
// CHECK-DAG: %[[EQ:.+]] = icmp eq i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R0:.+]] = icmp slt i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R1:.+]] = icmp ult i32 %[[A1]], %[[B1]] | ||
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[R1]], i1 %[[R0]] | ||
// CHECK-NEXT: ret i1 %[[R]] | ||
a < b | ||
} | ||
|
||
// CHECK-LABEL: @check_le( | ||
// CHECK-SAME: i32{{.+}}%[[A0:.+]], i32{{.+}}%[[A1:.+]], i32{{.+}}%[[B0:.+]], i32{{.+}}%[[B1:.+]]) | ||
#[no_mangle] | ||
pub fn check_le(a: Foo, b: Foo) -> bool { | ||
// CHECK-DAG: %[[EQ:.+]] = icmp eq i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R0:.+]] = icmp sle i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R1:.+]] = icmp ule i32 %[[A1]], %[[B1]] | ||
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[R1]], i1 %[[R0]] | ||
// CHECK-NEXT: ret i1 %[[R]] | ||
a <= b | ||
} | ||
|
||
// CHECK-LABEL: @check_gt( | ||
// CHECK-SAME: i32{{.+}}%[[A0:.+]], i32{{.+}}%[[A1:.+]], i32{{.+}}%[[B0:.+]], i32{{.+}}%[[B1:.+]]) | ||
#[no_mangle] | ||
pub fn check_gt(a: Foo, b: Foo) -> bool { | ||
// CHECK-DAG: %[[EQ:.+]] = icmp eq i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R0:.+]] = icmp sgt i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R1:.+]] = icmp ugt i32 %[[A1]], %[[B1]] | ||
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[R1]], i1 %[[R0]] | ||
// CHECK-NEXT: ret i1 %[[R]] | ||
a > b | ||
} | ||
|
||
// CHECK-LABEL: @check_ge( | ||
// CHECK-SAME: i32{{.+}}%[[A0:.+]], i32{{.+}}%[[A1:.+]], i32{{.+}}%[[B0:.+]], i32{{.+}}%[[B1:.+]]) | ||
#[no_mangle] | ||
pub fn check_ge(a: Foo, b: Foo) -> bool { | ||
// CHECK-DAG: %[[EQ:.+]] = icmp eq i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R0:.+]] = icmp sge i32 %[[A0]], %[[B0]] | ||
// CHECK-DAG: %[[R1:.+]] = icmp uge i32 %[[A1]], %[[B1]] | ||
// CHECK: %[[R:.+]] = select i1 %[[EQ]], i1 %[[R1]], i1 %[[R0]] | ||
// CHECK-NEXT: ret i1 %[[R]] | ||
a >= b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters