-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Three Codegen Tests #134626
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
base: master
Are you sure you want to change the base?
Add Three Codegen Tests #134626
Changes from all commits
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,31 @@ | ||
//@ assembly-output: emit-asm | ||
//@ only-x86_64 | ||
//@ ignore-sgx Test incompatible with LVI mitigations | ||
//@ compile-flags: -C opt-level=3 | ||
//! Ensure that indexing a slice with `bool` does not | ||
//! generate any redundant `jmp` and `and` instructions. | ||
//! Discovered in issue #123216. | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
fn f(a: u32, b: bool, c: bool, d: &mut [u128; 2]) { | ||
// CHECK-LABEL: f: | ||
// CHECK: testl %esi, %esi | ||
// CHECK: je | ||
// CHECK: xorb %dl, %dil | ||
// CHECK: orb $1, (%rcx) | ||
// CHECK: movzbl %dil, %eax | ||
// CHECK: andl $1, %eax | ||
// CHECK: shll $4, %eax | ||
// CHECK: orb $1, (%rcx,%rax) | ||
// CHECK-NOT: jmp | ||
// CHECK-NOT: andl %dil, $1 | ||
// CHECK: retq | ||
veera-sivarajan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut a = a & 1 != 0; | ||
if b { | ||
a ^= c; | ||
d[0] |= 1; | ||
} | ||
d[a as usize] |= 1; | ||
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bunch of kinda-random unjustified code. What's special about it? What makes it worth us having a test for it? Can we focus it way more somehow? I ask because this is the kind of test that tends to rot -- people look at it, there's one assembly instruction different, go "eh, probably fine" and just update the What changed? Where was it fixed? Can we add a more specific test somehow? If we don't already have a test for "we can eliminate the bounds check for indexing with bool into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Especially since, as you can see by the failure in bors, doing this in assembly coupled it to the calling convention, so it can't pass on both linux and windows with hard-coded register names like this. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//@ compile-flags: -C opt-level=3 | ||
//! Ensure that `.get()` on `std::num::NonZero*` types do not | ||
//! check for zero equivalency. | ||
//! Discovered in issue #49572. | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
pub fn foo(x: std::num::NonZeroU32) -> bool { | ||
// CHECK-LABEL: @foo( | ||
// CHECK: ret i1 true | ||
x.get() != 0 | ||
} | ||
|
||
#[no_mangle] | ||
pub fn bar(x: std::num::NonZeroI64) -> bool { | ||
// CHECK-LABEL: @bar( | ||
// CHECK: ret i1 true | ||
x.get() != 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//@ compile-flags: -C opt-level=3 | ||
//! Ensure that matching on `x % 5` generates an unreachable | ||
//! branch for values greater than 4. | ||
//! Discovered in issue #93514. | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
pub unsafe fn parse0(x: u32) -> u32 { | ||
// CHECK-LABEL: i32 @parse0( | ||
// CHECK: [[_2:%.*]] = urem | ||
// CHECK-NEXT: switch i32 [[_2]], label %[[DEFAULT_UNREACHABLE1:.*]] [ | ||
// CHECK-NEXT: i32 0 | ||
// CHECK-NEXT: i32 1 | ||
// CHECK-NEXT: i32 2 | ||
// CHECK-NEXT: i32 3 | ||
// CHECK-NEXT: i32 4 | ||
// CHECK-NEXT: ] | ||
// CHECK: [[DEFAULT_UNREACHABLE1]]: | ||
// CHECK-NEXT: unreachable | ||
// CHECK: ret i32 | ||
match x % 5 { | ||
0 => f1(x), | ||
1 => f2(x), | ||
2 => f3(x), | ||
3 => f4(x), | ||
4 => f5(x), | ||
_ => eliminate_me(), | ||
} | ||
} | ||
|
||
extern "Rust" { | ||
fn eliminate_me() -> u32; | ||
fn f1(x: u32) -> u32; | ||
fn f2(x: u32) -> u32; | ||
fn f3(x: u32) -> u32; | ||
fn f4(x: u32) -> u32; | ||
fn f5(x: u32) -> u32; | ||
} |
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.
Just a question: should this be an assembly test?
The IR change was introduced by llvm/llvm-project#84628, and this is not a backend change.
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.
Yeah, I think assembly test would be better because there isn't a big difference in the IR: https://rust.godbolt.org/z/sd7G1rsa7
Thanks