-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Added codegen tests for different forms of Option::or
#150564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
80acf74
bf2078b
66c4ead
3df06f5
a2fcb0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,175 @@ | ||||||||||||||||||||||
| // Tests output of multiple permutations of `Option::or` | ||||||||||||||||||||||
| //@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #![crate_type = "lib"] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| extern crate core; | ||||||||||||||||||||||
| use core::num::NonZero; | ||||||||||||||||||||||
rwardd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @or_match_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i1{{.+}}%0, i8 %1, i1{{.+}}%optb.0, i8 %optb.1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn or_match_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-DAG: or i1 %0 | ||||||||||||||||||||||
| // CHECK-DAG: select i1 %0 | ||||||||||||||||||||||
rwardd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // ret { i1, i8 } | ||||||||||||||||||||||
| match opta { | ||||||||||||||||||||||
| Some(x) => Some(x), | ||||||||||||||||||||||
| None => optb, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @or_match_alt_u8 | ||||||||||||||||||||||
rwardd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| // CHECK-SAME: (i1{{.+}}%opta.0, i8 %opta.1, i1{{.+}}%optb.0, i8 %optb.1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn or_match_alt_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-DAG: select i1 | ||||||||||||||||||||||
| // CHECK-DAG: or i1 | ||||||||||||||||||||||
rwardd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // ret { i1, i8 } | ||||||||||||||||||||||
| match opta { | ||||||||||||||||||||||
| Some(_) => opta, | ||||||||||||||||||||||
| None => optb, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @option_or_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i1{{.+}}%opta.0, i8 %opta.1, i1{{.+}}%optb.0, i8 %optb.1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn option_or_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-DAG: select i1 | ||||||||||||||||||||||
| // CHECK-DAG: or i1 | ||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // ret { i1, i8 } | ||||||||||||||||||||||
| opta.or(optb) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @if_some_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i1{{.+}}%opta.0, i8 %opta.1, i1{{.+}}%optb.0, i8 %optb.1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn if_some_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-DAG: select i1 | ||||||||||||||||||||||
| // CHECK-DAG: or i1 | ||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||||||||||||||||||||||
| // ret { i1, i8 } | ||||||||||||||||||||||
| if opta.is_some() { opta } else { optb } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Tests a case where an input is a type that is represented as `BackendRepr::Memory` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @or_match_slice_u8 | ||||||||||||||||||||||
rwardd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| // CHECK-SAME: (i16 %0, i16 %1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn or_match_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||||||||||||||||||||||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||||||||||||||||||||||
| // ret i16 | ||||||||||||||||||||||
| match opta { | ||||||||||||||||||||||
| Some(x) => Some(x), | ||||||||||||||||||||||
| None => optb, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @or_match_slice_alt_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i16 %0, i16 %1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn or_match_slice_alt_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||||||||||||||||||||||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||||||||||||||||||||||
| // ret i16 | ||||||||||||||||||||||
| match opta { | ||||||||||||||||||||||
| Some(_) => opta, | ||||||||||||||||||||||
| None => optb, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @option_or_slice_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i16 %0, i16 %1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn option_or_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||||||||||||||||||||||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||||||||||||||||||||||
| // ret i16 | ||||||||||||||||||||||
| opta.or(optb) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @if_some_slice_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i16 %0, i16 %1) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn if_some_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||||||||||||||||||||||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||||||||||||||||||||||
| // ret i16 | ||||||||||||||||||||||
| if opta.is_some() { opta } else { optb } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Test a niche optimization case of `NonZero<u8>` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // CHECK-LABEL: @or_match_nz_u8 | ||||||||||||||||||||||
| // CHECK-SAME: (i8{{.+}}%0, i8{{.+}}%optb) | ||||||||||||||||||||||
| #[no_mangle] | ||||||||||||||||||||||
| pub fn or_match_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> { | ||||||||||||||||||||||
| // CHECK: start: | ||||||||||||||||||||||
| // CHECK-NEXT: [[NOT_A:%.*]] = icmp eq i8 %0, 0 | ||||||||||||||||||||||
| // CHECK-NEXT: select i1 [[NOT_A]], i8 %optb, i8 %0 | ||||||||||||||||||||||
| // ret i8 | ||||||||||||||||||||||
|
||||||||||||||||||||||
| pub fn or_match_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> { | |
| // CHECK: start: | |
| // CHECK-NEXT: [[NOT_A:%.*]] = icmp eq i8 %0, 0 | |
| // CHECK-NEXT: select i1 [[NOT_A]], i8 %optb, i8 %0 | |
| // ret i8 | |
| pub fn or_match_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> { | |
| // CHECK: start: | |
| // CHECK: [[NOT_A:%.+]] = icmp eq i8 %0, 0 | |
| // CHECK: [[R:%.+]] = select i1 [[NOT_A]], i8 %optb, i8 %0 | |
| // CHECK: ret i8 [[R]] |
Since naming the values means that we're not concerned about other things showing up in the middle, and thus don't need to use the -NEXT that the ones looking at just the instructions do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And of course ditto the others below)
Uh oh!
There was an error while loading. Please reload this page.