-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #138073 - tmiasko:inline-asm-critical-edges, r=bjorn3
Break critical edges in inline asm before code generation An inline asm terminator defines outputs along its target edges -- a fallthrough target and labeled targets. Code generation implements this by inserting code directly into the target blocks. This approach works only if the target blocks don't have other predecessors. Establish required invariant by extending existing code that breaks critical edges before code generation. Fixes #137867. r? `@bjorn3`
- Loading branch information
Showing
2 changed files
with
81 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,37 @@ | ||
//@ only-x86_64 | ||
//@ compile-flags: -C no-prepopulate-passes | ||
#![feature(asm_goto)] | ||
#![feature(asm_goto_with_outputs)] | ||
#![crate_type = "lib"] | ||
use std::arch::asm; | ||
|
||
// Regression test for #137867. Check that critical edges have been split before code generation, | ||
// and so all stores to the asm output occur on disjoint paths without any of them jumping to | ||
// another callbr label. | ||
// | ||
// CHECK-LABEL: @f( | ||
// CHECK: [[OUT:%.*]] = callbr i32 asm | ||
// CHECK-NEXT: to label %[[BB0:.*]] [label %[[BB1:.*]], label %[[BB2:.*]]], | ||
// CHECK: [[BB1]]: | ||
// CHECK-NEXT: store i32 [[OUT]], ptr %a | ||
// CHECK-NEXT: br label %[[BBR:.*]] | ||
// CHECK: [[BB2]]: | ||
// CHECK-NEXT: store i32 [[OUT]], ptr %a | ||
// CHECK-NEXT: br label %[[BBR]] | ||
// CHECK: [[BB0]]: | ||
// CHECK-NEXT: store i32 [[OUT]], ptr %a | ||
// CHECK-NEXT: br label %[[BBR]] | ||
// CHECK: [[BBR]]: | ||
// CHECK-NEXT: [[RET:%.*]] = load i32, ptr %a | ||
// CHECK-NEXT: ret i32 [[RET]] | ||
#[unsafe(no_mangle)] | ||
pub unsafe fn f(mut a: u32) -> u32 { | ||
asm!( | ||
"jmp {} | ||
jmp {}", | ||
label {}, | ||
label {}, | ||
inout("eax") a, | ||
); | ||
a | ||
} |