Skip to content

Add tmm_reg clobbers #97097

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

Merged
merged 5 commits into from
May 18, 2022
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
9 changes: 6 additions & 3 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
InlineAsmRegClass::X86(
X86InlineAsmRegClass::x87_reg
| X86InlineAsmRegClass::mmx_reg
| X86InlineAsmRegClass::kreg0,
| X86InlineAsmRegClass::kreg0
| X86InlineAsmRegClass::tmm_reg,
) => unreachable!("clobber-only"),
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
Expand Down Expand Up @@ -692,7 +693,8 @@ fn modifier_to_llvm(
InlineAsmRegClass::X86(
X86InlineAsmRegClass::x87_reg
| X86InlineAsmRegClass::mmx_reg
| X86InlineAsmRegClass::kreg0,
| X86InlineAsmRegClass::kreg0
| X86InlineAsmRegClass::tmm_reg,
) => {
unreachable!("clobber-only")
}
Expand Down Expand Up @@ -766,7 +768,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
InlineAsmRegClass::X86(
X86InlineAsmRegClass::x87_reg
| X86InlineAsmRegClass::mmx_reg
| X86InlineAsmRegClass::kreg0,
| X86InlineAsmRegClass::kreg0
| X86InlineAsmRegClass::tmm_reg,
) => {
unreachable!("clobber-only")
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ symbols! {
thread_local_macro,
thumb2,
thumb_mode: "thumb-mode",
tmm_reg,
todo_macro,
tool_attributes,
tool_lints,
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_target/src/asm/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def_reg_class! {
kreg0,
mmx_reg,
x87_reg,
tmm_reg,
}
}

Expand All @@ -41,6 +42,7 @@ impl X86InlineAsmRegClass {
Self::xmm_reg | Self::ymm_reg | Self::zmm_reg => &['x', 'y', 'z'],
Self::kreg | Self::kreg0 => &[],
Self::mmx_reg | Self::x87_reg => &[],
Self::tmm_reg => &[],
}
}

Expand Down Expand Up @@ -80,6 +82,7 @@ impl X86InlineAsmRegClass {
},
Self::kreg | Self::kreg0 => None,
Self::mmx_reg | Self::x87_reg => None,
Self::tmm_reg => None,
}
}

Expand All @@ -98,6 +101,7 @@ impl X86InlineAsmRegClass {
Self::zmm_reg => Some(('z', "zmm0")),
Self::kreg | Self::kreg0 => None,
Self::mmx_reg | Self::x87_reg => None,
Self::tmm_reg => None,
}
}

Expand Down Expand Up @@ -135,6 +139,7 @@ impl X86InlineAsmRegClass {
},
Self::kreg0 => &[],
Self::mmx_reg | Self::x87_reg => &[],
Self::tmm_reg => &[],
}
}
}
Expand Down Expand Up @@ -320,6 +325,14 @@ def_regs! {
st5: x87_reg = ["st(5)"],
st6: x87_reg = ["st(6)"],
st7: x87_reg = ["st(7)"],
tmm0: tmm_reg = ["tmm0"] % x86_64_only,
tmm1: tmm_reg = ["tmm1"] % x86_64_only,
tmm2: tmm_reg = ["tmm2"] % x86_64_only,
tmm3: tmm_reg = ["tmm3"] % x86_64_only,
tmm4: tmm_reg = ["tmm4"] % x86_64_only,
tmm5: tmm_reg = ["tmm5"] % x86_64_only,
tmm6: tmm_reg = ["tmm6"] % x86_64_only,
tmm7: tmm_reg = ["tmm7"] % x86_64_only,
#error = ["bp", "bpl", "ebp", "rbp"] =>
"the frame pointer cannot be used as an operand for inline asm",
#error = ["sp", "spl", "esp", "rsp"] =>
Expand Down
7 changes: 7 additions & 0 deletions src/test/codegen/asm-target-clobbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

use std::arch::asm;

// CHECK-LABEL: @avx512_clobber
Copy link
Member

Choose a reason for hiding this comment

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

Should be @amx_clobber I think.

Copy link
Contributor Author

@chorman0773 chorman0773 May 17, 2022

Choose a reason for hiding this comment

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

Yeah, you'd be right 🤦
I'll fix that in the morning.

// base: call void asm sideeffect inteldialect "", "~{tmm0}"()
#[no_mangle]
pub unsafe fn amx_clobber() {
asm!("", out("tmm0") _, options(nostack, nomem, preserves_flags));
}

// CHECK-LABEL: @avx512_clobber
// base: call void asm sideeffect inteldialect "", "~{xmm31}"()
// avx512: call float asm sideeffect inteldialect "", "=&{xmm31}"()
Expand Down