-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add assembly test for -Zreg-struct-return
option
#145382
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
Open
winstonallo
wants to merge
7
commits into
rust-lang:master
Choose a base branch
from
winstonallo:reg-struct-return-asm-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d06c2d4
Add test file for reg-struct-return
winstonallo 24a767d
Add assembly tests for `-Zreg-struct-return`
winstonallo fc67ace
Improve test description in comment
winstonallo 427a183
Add better test description
winstonallo f4a9317
Add tests for < 8 and > 8 bytes structs
winstonallo 3518ac1
Simplify WITHOUT test in pivot_call
winstonallo fcf55d5
Generalize target registers in tests
winstonallo 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
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,62 @@ | ||
// Tests that -Zreg-struct-return changes ABI for small struct returns | ||
// from hidden-pointer convention to register-return convention on x86. | ||
//@ add-core-stubs | ||
//@ assembly-output: emit-asm | ||
//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static | ||
//@ revisions: WITH WITHOUT | ||
//@[WITH] compile-flags: -Zreg-struct-return | ||
//@ needs-llvm-components: x86 | ||
|
||
#![feature(no_core)] | ||
#![no_std] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
extern crate minicore; | ||
use minicore::*; | ||
|
||
struct div_t { | ||
quot: i32, | ||
rem: i32, | ||
} | ||
|
||
unsafe extern "C" { | ||
fn div(numerator: i32, denominator: i32) -> div_t; | ||
} | ||
|
||
#[unsafe(no_mangle)] | ||
pub unsafe extern "C" fn direct_construction(numerator: i32, denominator: i32) -> div_t { | ||
// WITH-LABEL: direct_construction | ||
// WITH: movl $42, %eax | ||
// WITH: movl $42, %edx | ||
// WITH: retl | ||
|
||
// WITHOUT-LABEL: direct_construction | ||
// WITHOUT: movl 4(%esp), %eax | ||
// WITHOUT: movl $42, (%eax) | ||
// WITHOUT: movl $42, 4(%eax) | ||
// WITHOUT: retl $4 | ||
div_t { quot: 42, rem: 42 } | ||
} | ||
|
||
#[unsafe(no_mangle)] | ||
pub unsafe extern "C" fn builtin_call(numerator: i32, denominator: i32) -> div_t { | ||
// WITH-LABEL: builtin_call | ||
// WITH: jmp div | ||
|
||
// WITHOUT-LABEL: builtin_call | ||
// WITHOUT: pushl %esi | ||
// WITHOUT: subl $8, %esp | ||
// WITHOUT: movl 16(%esp), %esi | ||
// WITHOUT: subl $4, %esp | ||
// WITHOUT: pushl 28(%esp) | ||
// WITHOUT: pushl 28(%esp) | ||
// WITHOUT: pushl %esi | ||
// WITHOUT: calll div | ||
// WITHOUT: addl $12, %esp | ||
// WITHOUT: movl %esi, %eax | ||
// WITHOUT: addl $8, %esp | ||
// WITHOUT: popl %esi | ||
// WITHOUT: retl $4 | ||
div(numerator, denominator) | ||
} |
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.
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.
By the way, I am not sure how strict we want to be matching the entire stream of instructions for this case -- it could be improved or shuffled a bit by the backend.
On the other hand, this may be easy to relax if a newer LLVM changes it.
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.
Yea I was also wondering, it's definitely easy to relax later but would be nice to have a maintainer's opinion on this to make sure this test is not flaky. I am unfortunately not very familiar with how often LLVM changes this kind of stuff
Uh oh!
There was an error while loading. Please reload this page.
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.
I assume it would be fine to limit this to what differentiates it from the reg-struct-return assembly, so the
calll
and theretl $4
, what do you think?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, like in the new ones you just added, right?
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.
Looks like the code here was:
Which doesn't exist anymore. For reference though, here's a way-too-detailed answer:
The above is testing a lot: both the caller side and the callee side, as well as how
i32
gets passed. For ABI tests it's best to make each test function isolate one of those aspects, which gives you less to assert on. For checking returns usually that means returning some immediate value to test the callee side (like you have now), and then storing the result of a call (#145382 (comment)) to test the caller side. Then you basically only need to check that something gets written to the place you expect and can be more lax about how it gets there.LLVM's repo has a lot more assertions about exact instruction sequences (using
-NEXT
), but these are usually autogenerated and run without optimizations so it's not as likely to be volatile. An example that's fresh in my head: https://github.com/llvm/llvm-project/blob/c22ec9cde3708e0c7afd0909508a67ef9625aa4c/llvm/test/CodeGen/X86/i128-fp128-abi.ll. We tend to avoid such tests in this repo because it's more painful to update when things do change, and LLVM covers ABI things pretty well.For
CHECK:
directives where the ordering doesn't matter, FileCheck hasCHECK-DAG
. No need really to do this here, though it doesn't hurt if you feel like it (might make it possible to use the same test for the clif and gcc backends once/if those start getting asm tests).It also has a cool feature where you can bind a regex to a name and then use it later, useful if you know it will use a scratch register but don't care which https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-dag-directive.