[llvm] MIPS: Support '%w' token in inline asm template for MSA (PR #91920)
YunQiang Su via llvm-commits
llvm-commits at lists.llvm.org
Tue May 14 19:51:36 PDT 2024
https://github.com/wzssyqa updated https://github.com/llvm/llvm-project/pull/91920
>From 70e71ff64426cdb9f8baba4dedf2016bd57edae7 Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at gcc.gnu.org>
Date: Mon, 13 May 2024 14:40:57 +0800
Subject: [PATCH] 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.
---
llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h | 9 +++++++++
llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 11 +++++++----
llvm/test/CodeGen/Mips/msa/inline-asm.ll | 16 ++++++++++++++++
3 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
index 02ab5ede2c1a4..aa35e7db6bda4 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
@@ -135,6 +135,15 @@ namespace MipsII {
OPERAND_LAST_MIPS_MEM_IMM = OPERAND_MEM_SIMM9
};
}
+
+inline static MCRegister getMSARegFromFReg(MCRegister Reg) {
+ if (Reg >= Mips::F0 && Reg <= Mips::F31)
+ return Reg - Mips::F0 + Mips::W0;
+ else if (Reg >= Mips::D0_64 && Reg <= Mips::D31_64)
+ return Reg - Mips::D0_64 + Mips::W0;
+ else
+ return Mips::NoRegister;
+}
}
#endif
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 66b2b0de8d52a..dda33f9a18087 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -565,12 +565,15 @@ bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
}
break;
}
- case 'w':
- // Print MSA registers for the 'f' constraint
- // In LLVM, the 'w' modifier doesn't need to do anything.
- // We can just call printOperand as normal.
+ case 'w': {
+ MCRegister w = getMSARegFromFReg(MO.getReg());
+ if (w != Mips::NoRegister) {
+ O << '$' << MipsInstPrinter::getRegisterName(w);
+ return false;
+ }
break;
}
+ }
}
printOperand(MI, OpNum, O);
diff --git a/llvm/test/CodeGen/Mips/msa/inline-asm.ll b/llvm/test/CodeGen/Mips/msa/inline-asm.ll
index 57cd78a25647c..f84b11e05387e 100644
--- a/llvm/test/CodeGen/Mips/msa/inline-asm.ll
+++ b/llvm/test/CodeGen/Mips/msa/inline-asm.ll
@@ -32,3 +32,19 @@ entry:
store <4 x i32> %1, ptr @v4i32_r
ret void
}
+
+define dso_local double @test4(double noundef %a, double noundef %b, double noundef %c) {
+entry:
+ ; CHECK-LABEL: test4:
+ %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)
+ ; CHECK: fmadd.d $w{{([0-9]|[1-3][0-9])}}, $w{{([0-9]|[1-3][0-9])}}, $w{{([0-9]|[1-3][0-9])}}
+ ret double %0
+}
+
+define dso_local float @test5(float noundef %a, float noundef %b, float noundef %c) {
+entry:
+ ; CHECK-LABEL: test5:
+ %0 = tail call float asm sideeffect "fmadd.w ${0:w}, ${1:w}, ${2:w}", "=f,f,f,0,~{$1}"(float %b, float %c, float %a)
+ ; CHECK: fmadd.w $w{{([0-9]|[1-3][0-9])}}, $w{{([0-9]|[1-3][0-9])}}, $w{{([0-9]|[1-3][0-9])}}
+ ret float %0
+}
More information about the llvm-commits
mailing list