Skip to content

Commit c5f7c03

Browse files
committed
[X86] Add x, t and g modifiers for inline asm
This patch adds the x, t and g modifiers for inline asm from GCC. These will print a vector register as xmm*, ymm* or zmm* respectively. I also fixed register names with modifiers with inteldialect so they are no longer printed with a leading %. Patch by Amanieu d'Antras Differential Revision: https://reviews.llvm.org/D78977
1 parent a1bd5cd commit c5f7c03

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
407407
static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
408408
char Mode, raw_ostream &O) {
409409
Register Reg = MO.getReg();
410-
bool EmitPercent = true;
410+
bool EmitPercent = MO.getParent()->getInlineAsmDialect() == InlineAsm::AD_ATT;
411411

412412
if (!X86::GR8RegClass.contains(Reg) &&
413413
!X86::GR16RegClass.contains(Reg) &&
@@ -446,6 +446,42 @@ static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
446446
return false;
447447
}
448448

449+
static bool printAsmVRegister(X86AsmPrinter &P, const MachineOperand &MO,
450+
char Mode, raw_ostream &O) {
451+
unsigned Reg = MO.getReg();
452+
bool EmitPercent = MO.getParent()->getInlineAsmDialect() == InlineAsm::AD_ATT;
453+
454+
unsigned Index;
455+
if (X86::VR128XRegClass.contains(Reg))
456+
Index = Reg - X86::XMM0;
457+
else if (X86::VR256XRegClass.contains(Reg))
458+
Index = Reg - X86::YMM0;
459+
else if (X86::VR512RegClass.contains(Reg))
460+
Index = Reg - X86::ZMM0;
461+
else
462+
return true;
463+
464+
switch (Mode) {
465+
default: // Unknown mode.
466+
return true;
467+
case 'x': // Print V4SFmode register
468+
Reg = X86::XMM0 + Index;
469+
break;
470+
case 't': // Print V8SFmode register
471+
Reg = X86::YMM0 + Index;
472+
break;
473+
case 'g': // Print V16SFmode register
474+
Reg = X86::ZMM0 + Index;
475+
break;
476+
}
477+
478+
if (EmitPercent)
479+
O << '%';
480+
481+
O << X86ATTInstPrinter::getRegisterName(Reg);
482+
return false;
483+
}
484+
449485
/// PrintAsmOperand - Print out an operand for an inline asm expression.
450486
///
451487
bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
@@ -520,6 +556,14 @@ bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
520556
PrintOperand(MI, OpNo, O);
521557
return false;
522558

559+
case 'x': // Print V4SFmode register
560+
case 't': // Print V8SFmode register
561+
case 'g': // Print V16SFmode register
562+
if (MO.isReg())
563+
return printAsmVRegister(*this, MO, ExtraCode[0], O);
564+
PrintOperand(MI, OpNo, O);
565+
return false;
566+
523567
case 'P': // This is the operand of a call, treat specially.
524568
PrintPCRelImm(MI, OpNo, O);
525569
return false;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
define void @test1() {
4+
; CHECK-LABEL: test1:
5+
; CHECK: vmovaps %xmm0, %xmm0
6+
; CHECK: vmovaps %ymm0, %ymm0
7+
; CHECK: vmovaps %zmm0, %zmm0
8+
tail call void asm sideeffect "vmovaps ${0:x}, ${0:x}", "{xmm0},~{dirflag},~{fpsr},~{flags}"(i32 0)
9+
tail call void asm sideeffect "vmovaps ${0:t}, ${0:t}", "{xmm0},~{dirflag},~{fpsr},~{flags}"(i32 0)
10+
tail call void asm sideeffect "vmovaps ${0:g}, ${0:g}", "{xmm0},~{dirflag},~{fpsr},~{flags}"(i32 0)
11+
ret void
12+
}
13+
14+
define void @test2() {
15+
; CHECK-LABEL: test2:
16+
; CHECK: vmovaps %xmm0, %xmm0
17+
; CHECK: vmovaps %ymm0, %ymm0
18+
; CHECK: vmovaps %zmm0, %zmm0
19+
tail call void asm sideeffect inteldialect "vmovaps ${0:x}, ${0:x}", "{xmm0},~{dirflag},~{fpsr},~{flags}"(i32 0)
20+
tail call void asm sideeffect inteldialect "vmovaps ${0:t}, ${0:t}", "{xmm0},~{dirflag},~{fpsr},~{flags}"(i32 0)
21+
tail call void asm sideeffect inteldialect "vmovaps ${0:g}, ${0:g}", "{xmm0},~{dirflag},~{fpsr},~{flags}"(i32 0)
22+
ret void
23+
}
24+
25+
define void @test3() {
26+
; CHECK-LABEL: test3:
27+
; CHECK: movb %al, %al
28+
; CHECK: movb %ah, %ah
29+
; CHECK: movw %ax, %ax
30+
; CHECK: movl %eax, %eax
31+
; CHECK: movq %rax, %rax
32+
tail call void asm sideeffect "mov ${0:b}, ${0:b}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
33+
tail call void asm sideeffect "mov ${0:h}, ${0:h}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
34+
tail call void asm sideeffect "mov ${0:w}, ${0:w}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
35+
tail call void asm sideeffect "mov ${0:k}, ${0:k}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
36+
tail call void asm sideeffect "mov ${0:q}, ${0:q}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
37+
ret void
38+
}
39+
40+
define void @test4() {
41+
; CHECK-LABEL: test4:
42+
; CHECK: movb %al, %al
43+
; CHECK: movb %ah, %ah
44+
; CHECK: movw %ax, %ax
45+
; CHECK: movl %eax, %eax
46+
; CHECK: movq %rax, %rax
47+
tail call void asm sideeffect inteldialect "mov ${0:b}, ${0:b}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
48+
tail call void asm sideeffect inteldialect "mov ${0:h}, ${0:h}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
49+
tail call void asm sideeffect inteldialect "mov ${0:w}, ${0:w}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
50+
tail call void asm sideeffect inteldialect "mov ${0:k}, ${0:k}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
51+
tail call void asm sideeffect inteldialect "mov ${0:q}, ${0:q}", "{eax},~{dirflag},~{fpsr},~{flags}"(i32 0)
52+
ret void
53+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; RUN: not llc -mtriple=x86_64-- < %s 2>&1 | FileCheck %s
22

3-
;CHECK: error: invalid operand in inline asm: 'vmovd ${1:x}, $0'
3+
;CHECK: error: invalid operand in inline asm: 'vmovd ${1:k}, $0'
44
define i32 @foo() {
55
entry:
6-
%0 = tail call i32 asm sideeffect "vmovd ${1:x}, $0", "=r,x,~{dirflag},~{fpsr},~{flags}"(<2 x i64> <i64 240518168632, i64 240518168632>)
6+
%0 = tail call i32 asm sideeffect "vmovd ${1:k}, $0", "=r,x,~{dirflag},~{fpsr},~{flags}"(<2 x i64> <i64 240518168632, i64 240518168632>)
77
ret i32 %0
88
}

0 commit comments

Comments
 (0)