[llvm] [RISCV] Add support for inline asm constraint vd (PR #111653)
Jim Lin via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 02:27:28 PDT 2024
https://github.com/tclin914 created https://github.com/llvm/llvm-project/pull/111653
It constrains vector registers excluding v0.
This patch also adds a testcase for constraints vr, vd and vm.
>From 80768f580d4ef6b9841b22ee5b287a87d9f25951 Mon Sep 17 00:00:00 2001
From: Jim Lin <jim at andestech.com>
Date: Wed, 9 Oct 2024 11:37:46 +0800
Subject: [PATCH] [RISCV] Add support for inline asm constraint vd
It constrains vector registers excluding v0.
This patch also adds a testcase for constraints vr, vd and vm.
---
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 15 ++++-
.../CodeGen/RISCV/inline-asm-v-constraint.ll | 66 +++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/RISCV/inline-asm-v-constraint.ll
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 463887b8b55e61..0c8fd324edd1cf 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20340,7 +20340,7 @@ RISCVTargetLowering::getConstraintType(StringRef Constraint) const {
return C_Other;
}
} else {
- if (Constraint == "vr" || Constraint == "vm")
+ if (Constraint == "vr" || Constraint == "vd" || Constraint == "vm")
return C_RegisterClass;
}
return TargetLowering::getConstraintType(Constraint);
@@ -20388,6 +20388,19 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
if (TRI->isTypeLegalForClass(*RC, VT.SimpleTy))
return std::make_pair(0U, RC);
}
+ } else if (Constraint == "vd") {
+ for (const auto *RC :
+ {&RISCV::VRNoV0RegClass, &RISCV::VRM2NoV0RegClass,
+ &RISCV::VRM4NoV0RegClass, &RISCV::VRM8NoV0RegClass,
+ &RISCV::VRN2M1NoV0RegClass, &RISCV::VRN3M1NoV0RegClass,
+ &RISCV::VRN4M1NoV0RegClass, &RISCV::VRN5M1NoV0RegClass,
+ &RISCV::VRN6M1NoV0RegClass, &RISCV::VRN7M1NoV0RegClass,
+ &RISCV::VRN8M1NoV0RegClass, &RISCV::VRN2M2NoV0RegClass,
+ &RISCV::VRN3M2NoV0RegClass, &RISCV::VRN4M2NoV0RegClass,
+ &RISCV::VRN2M4NoV0RegClass}) {
+ if (TRI->isTypeLegalForClass(*RC, VT.SimpleTy))
+ return std::make_pair(0U, RC);
+ }
} else if (Constraint == "vm") {
if (TRI->isTypeLegalForClass(RISCV::VMV0RegClass, VT.SimpleTy))
return std::make_pair(0U, &RISCV::VMV0RegClass);
diff --git a/llvm/test/CodeGen/RISCV/inline-asm-v-constraint.ll b/llvm/test/CodeGen/RISCV/inline-asm-v-constraint.ll
new file mode 100644
index 00000000000000..c04e4fea7b2c29
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/inline-asm-v-constraint.ll
@@ -0,0 +1,66 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=RV32I %s
+; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=RV64I %s
+
+define <vscale x 1 x i8> @constraint_vr(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1) nounwind {
+; RV32I-LABEL: constraint_vr:
+; RV32I: # %bb.0:
+; RV32I-NEXT: #APP
+; RV32I-NEXT: vadd.vv v8, v8, v9
+; RV32I-NEXT: #NO_APP
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: constraint_vr:
+; RV64I: # %bb.0:
+; RV64I-NEXT: #APP
+; RV64I-NEXT: vadd.vv v8, v8, v9
+; RV64I-NEXT: #NO_APP
+; RV64I-NEXT: ret
+ %a = tail call <vscale x 1 x i8> asm "vadd.vv $0, $1, $2", "=^vr,^vr,^vr"(
+ <vscale x 1 x i8> %0, <vscale x 1 x i8> %1)
+ ret <vscale x 1 x i8> %a
+}
+
+define <vscale x 1 x i8> @constraint_vd(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1) nounwind {
+; RV32I-LABEL: constraint_vd:
+; RV32I: # %bb.0:
+; RV32I-NEXT: #APP
+; RV32I-NEXT: vadd.vv v8, v8, v9
+; RV32I-NEXT: #NO_APP
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: constraint_vd:
+; RV64I: # %bb.0:
+; RV64I-NEXT: #APP
+; RV64I-NEXT: vadd.vv v8, v8, v9
+; RV64I-NEXT: #NO_APP
+; RV64I-NEXT: ret
+ %a = tail call <vscale x 1 x i8> asm "vadd.vv $0, $1, $2", "=^vd,^vr,^vr"(
+ <vscale x 1 x i8> %0, <vscale x 1 x i8> %1)
+ ret <vscale x 1 x i8> %a
+}
+
+define <vscale x 1 x i1> @constraint_vm(<vscale x 1 x i1> %0, <vscale x 1 x i1> %1) nounwind {
+; RV32I-LABEL: constraint_vm:
+; RV32I: # %bb.0:
+; RV32I-NEXT: vmv1r.v v9, v0
+; RV32I-NEXT: vmv1r.v v0, v8
+; RV32I-NEXT: #APP
+; RV32I-NEXT: vadd.vv v0, v9, v0
+; RV32I-NEXT: #NO_APP
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: constraint_vm:
+; RV64I: # %bb.0:
+; RV64I-NEXT: vmv1r.v v9, v0
+; RV64I-NEXT: vmv1r.v v0, v8
+; RV64I-NEXT: #APP
+; RV64I-NEXT: vadd.vv v0, v9, v0
+; RV64I-NEXT: #NO_APP
+; RV64I-NEXT: ret
+ %a = tail call <vscale x 1 x i1> asm "vadd.vv $0, $1, $2", "=^vr,^vr,^vm"(
+ <vscale x 1 x i1> %0, <vscale x 1 x i1> %1)
+ ret <vscale x 1 x i1> %a
+}
More information about the llvm-commits
mailing list