Skip to content
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

Mark inout asm! operands as used in liveness pass #77976

Merged
merged 6 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
hir::InlineAsmOperand::InOut { expr, .. } => {
succ = self.propagate_through_place_components(expr, succ);
succ = self.propagate_through_expr(expr, succ);
Copy link
Member

@nagisa nagisa Oct 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't dig too deep into this, but looking at Assign code as an example, I suspect this may need both propagate_through_place_components and propagate_through_expr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it was determined that propagate_through_place_components would be the necessary call here in order to avoid improperly setting the inout expr as its own successor/predecessory.

}
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
if let Some(expr) = out_expr {
Expand Down
36 changes: 36 additions & 0 deletions src/test/ui/liveness/liveness-issue-77915.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Ensure inout asm! operands are marked as used by the liveness pass

// only-x86_64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test could also be made architecture independent by doing something like this:

unsafe fn rep_movsb(mut src: *const u8) {
    asm!("/*{0}*/", inout(reg) src);
}

It would allow testing this by people who use something else than x86_64 as a host.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest changes, thanks!

// check-pass

#![feature(asm)]
#![allow(dead_code)]
#![deny(unused_variables)]

// Tests the single variable inout case
unsafe fn rep_movsb(mut dest: *mut u8, mut src: *const u8, mut n: usize) -> *mut u8 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test that ensures projections work correctly as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of test cases for field projection, thanks!

while n != 0 {
asm!(
"rep movsb",
inout("rcx") n,
inout("rsi") src,
inout("rdi") dest,
);
}
dest
}

// Tests the split inout case
unsafe fn rep_movsb2(mut dest: *mut u8, mut src: *const u8, mut n: usize) -> *mut u8 {
while n != 0 {
asm!(
"rep movsb",
inout("rcx") n,
inout("rsi") src => src,
inout("rdi") dest,
);
}
dest
}

fn main() {}