Skip to content

Commit 6c7cc15

Browse files
committed
MIPS: Support '%w' token in inline asm template for MSA
MSA registers share the FPRs as its bottom half. So that we can use MSA instructions to work with normal float/double: double a, b, c; asm volatile ("fmadd.d %w0, %w1, %w2" : "+f"(a) : "f"(b), "f"(c)); GCC has support it for quite long time.
1 parent 5ca3685 commit 6c7cc15

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,27 @@ bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
565565
}
566566
break;
567567
}
568-
case 'w':
569-
// Print MSA registers for the 'f' constraint
570-
// In LLVM, the 'w' modifier doesn't need to do anything.
571-
// We can just call printOperand as normal.
568+
case 'w': {
569+
// Support to use MSA instructions on FPR.
570+
// double a, b, c;
571+
// asm volatile ("fmadd.d %w0, %w1, %w2" : "+f"(a) : "f"(b), "f"(c))
572+
const char *RegNameF =
573+
MipsInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
574+
if (RegNameF[0] != 'f')
575+
break;
576+
// Now we have 'fXX', let's find 'wXX'.
577+
for (const char *RegNameW = RegNameF; RegNameW < RegNameF + 32;
578+
RegNameW++) {
579+
if (RegNameW[0] != 'w')
580+
continue;
581+
if (StringRef(RegNameF + 1) == StringRef(RegNameW + 1)) {
582+
O << '$' << RegNameW;
583+
return false;
584+
}
585+
}
572586
break;
573587
}
588+
}
574589
}
575590

576591
printOperand(MI, OpNum, O);

llvm/test/CodeGen/Mips/msa/inline-asm.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ entry:
3232
store <4 x i32> %1, ptr @v4i32_r
3333
ret void
3434
}
35+
36+
define dso_local double @test4(double noundef %a, double noundef %b, double noundef %c) {
37+
entry:
38+
; CHECK-LABEL: test4:
39+
%0 = tail call double asm sideeffect "fmadd.d ${0:w}, ${1:w}, ${2:w}", "=f,f,f,0,~{$1}"(double %b, double %c, double %a)
40+
; CHECK: fmadd.d $w{{([0-9]|[1-3][0-9])}}, $w{{([0-9]|[1-3][0-9])}}, $w{{([0-9]|[1-3][0-9])}}
41+
ret double %0
42+
}

0 commit comments

Comments
 (0)