-
-
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
Merged
+174
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
80acf74
test: added codegen tests for permutations of `Option::or`
rwardd bf2078b
fix: add `CHECK-SAME` labels to verify generated function type for `u…
rwardd 66c4ead
fix: added further `CHECK-SAME` labels and replaced all `struct` inpu…
rwardd 3df06f5
fix: use `std::num::NonZero` instead of `extern crate` and extend inf…
rwardd a2fcb0d
fix: add `CHECK` directives to `ret` comments and be more pervasive w…
rwardd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
tests/codegen-llvm/issues/multiple-option-or-permutations.rs
This file contains hidden or 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,174 @@ | ||
| // Tests output of multiple permutations of `Option::or` | ||
| //@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| use std::num::NonZero; | ||
|
|
||
| // 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: [[A_OR_B:%.+]] = select i1 %0, i8 %1, i8 %optb.1 | ||
| // CHECK-DAG: [[IS_SOME:%.+]] = or i1 {{%0, %optb.0|%optb.0, %0}} | ||
| // CHECK-NEXT: [[FLAG:%.+]] = insertvalue { i1, i8 } poison, i1 [[IS_SOME]], 0 | ||
| // CHECK-NEXT: [[R:%.+]] = insertvalue { i1, i8 } [[FLAG]], i8 [[A_OR_B]], 1 | ||
| // CHECK: ret { i1, i8 } [[R]] | ||
| 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: [[A_OR_B:%.+]] = select i1 %opta.0, i8 %opta.1, i8 %optb.1 | ||
| // CHECK-DAG: [[IS_SOME:%.+]] = or i1 {{%opta.0, %optb.0|%optb.0, %opta.0}} | ||
| // CHECK-NEXT: [[FLAG:%.+]] = insertvalue { i1, i8 } poison, i1 [[IS_SOME]], 0 | ||
| // CHECK-NEXT: [[R:%.+]] = insertvalue { i1, i8 } [[FLAG]], i8 [[A_OR_B]], 1 | ||
| // CHECK: ret { i1, i8 } [[R]] | ||
| 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: [[A_OR_B:%.+]] = select i1 %opta.0, i8 %opta.1, i8 %optb.1 | ||
| // CHECK-DAG: [[IS_SOME:%.+]] = or i1 {{%opta.0, %optb.0|%optb.0, %opta.0}} | ||
| // CHECK-NEXT: [[FLAG:%.+]] = insertvalue { i1, i8 } poison, i1 [[IS_SOME]], 0 | ||
| // CHECK-NEXT: [[R:%.+]] = insertvalue { i1, i8 } [[FLAG]], i8 [[A_OR_B]], 1 | ||
| // CHECK: ret { i1, i8 } [[R]] | ||
| 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: [[A_OR_B:%.+]] = select i1 %opta.0, i8 %opta.1, i8 %optb.1 | ||
| // CHECK-DAG: [[IS_SOME:%.+]] = or i1 {{%opta.0, %optb.0|%optb.0, %opta.0}} | ||
| // CHECK-NEXT: [[FLAG:%.+]] = insertvalue { i1, i8 } poison, i1 [[IS_SOME]], 0 | ||
| // CHECK-NEXT: [[R:%.+]] = insertvalue { i1, i8 } [[FLAG]], i8 [[A_OR_B]], 1 | ||
| // CHECK: ret { i1, i8 } [[R]] | ||
| 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: [[SOME_A:%.+]] = trunc i16 %0 to i1 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[SOME_A]], i16 %0, i16 %1 | ||
| // CHECK: ret i16 [[R]] | ||
| 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: [[SOME_A:%.+]] = trunc i16 %0 to i1 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[SOME_A]], i16 %0, i16 %1 | ||
| // CHECK: ret i16 [[R]] | ||
| 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: [[SOME_A:%.+]] = trunc i16 %0 to i1 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[SOME_A]], i16 %0, i16 %1 | ||
| // CHECK: ret i16 [[R]] | ||
| 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: [[SOME_A:%.+]] = trunc i16 %0 to i1 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[SOME_A]], i16 %0, i16 %1 | ||
| // CHECK: ret i16 [[R]] | ||
| 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: [[R:%.+]] = select i1 [[NOT_A]], i8 %optb, i8 %0 | ||
| // CHECK: ret i8 [[R]] | ||
| match opta { | ||
| Some(x) => Some(x), | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @or_match_alt_nz_u8 | ||
| // CHECK-SAME: (i8{{.+}}%opta, i8{{.+}}%optb) | ||
| #[no_mangle] | ||
| pub fn or_match_alt_nz_u8( | ||
| opta: Option<NonZero<u8>>, | ||
| optb: Option<NonZero<u8>>, | ||
| ) -> Option<NonZero<u8>> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: [[NOT_A:%.+]] = icmp eq i8 %opta, 0 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[NOT_A]], i8 %optb, i8 %opta | ||
| // CHECK: ret i8 [[R]] | ||
| match opta { | ||
| Some(_) => opta, | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @option_or_nz_u8 | ||
| // CHECK-SAME: (i8{{.+}}%opta, i8{{.+}}%optb) | ||
| #[no_mangle] | ||
| pub fn option_or_nz_u8( | ||
| opta: Option<NonZero<u8>>, | ||
| optb: Option<NonZero<u8>>, | ||
| ) -> Option<NonZero<u8>> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: [[NOT_A:%.+]] = icmp eq i8 %opta, 0 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[NOT_A]], i8 %optb, i8 %opta | ||
| // CHECK: ret i8 [[R]] | ||
| opta.or(optb) | ||
| } | ||
|
|
||
| // CHECK-LABEL: @if_some_nz_u8 | ||
| // CHECK-SAME: (i8{{.+}}%opta, i8{{.+}}%optb) | ||
| #[no_mangle] | ||
| pub fn if_some_nz_u8(opta: Option<NonZero<u8>>, optb: Option<NonZero<u8>>) -> Option<NonZero<u8>> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: [[NOT_A:%.+]] = icmp eq i8 %opta, 0 | ||
| // CHECK-NEXT: [[R:%.+]] = select i1 [[NOT_A]], i8 %optb, i8 %opta | ||
| // CHECK: ret i8 [[R]] | ||
| if opta.is_some() { opta } else { optb } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.