Skip to content

Commit

Permalink
Require target features to match exactly during inlining
Browse files Browse the repository at this point in the history
In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
  • Loading branch information
tmiasko committed Oct 24, 2023
1 parent b3cfd5b commit 011b260
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,8 @@ impl<'tcx> Inliner<'tcx> {
return Err("incompatible instruction set");
}

for feature in &callee_attrs.target_features {
if !self.codegen_fn_attrs.target_features.contains(feature) {
return Err("incompatible target feature");
}
if callee_attrs.target_features != self.codegen_fn_attrs.target_features {
return Err("incompatible target features");
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/inline/inline_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub unsafe fn f1() {

// CHECK-LABEL: fn f2()
// CHECK: bb0: {
// CHECK-NEXT: return;
// CHECK-NEXT: nop()
#[target_feature(enable = "avx")]
pub unsafe fn f2() {
nop();
Expand Down

0 comments on commit 011b260

Please sign in to comment.