Skip to content

Commit 12bb361

Browse files
committed
fixup! [RISCV][llvm] Support fixed-length vector inline assembly constraints
1 parent 48bf19c commit 12bb361

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

clang/test/CodeGen/RISCV/riscv-inline-asm-fixed-length-vector.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99

1010
// Test RISC-V V-extension fixed-length vector inline assembly constraints.
1111
#include <riscv_vector.h>
12+
#include <stdbool.h>
1213

1314
typedef vbool1_t fixed_bool1_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)));
1415
typedef vint32m1_t fixed_i32m1_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)));
1516
typedef vint8mf2_t fixed_i8mf2_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen / 2)));
1617

18+
typedef bool bx2 __attribute__((ext_vector_type(16)));
19+
typedef int i32x2 __attribute__((ext_vector_type(2)));
20+
typedef char i8x4 __attribute__((ext_vector_type(4)));
21+
1722
fixed_i32m1_t test_vr(fixed_i32m1_t a) {
1823
// CHECK-LABEL: define{{.*}} @test_vr
1924
// CHECK: %0 = tail call <4 x i32> asm sideeffect "vadd.vv $0, $1, $2", "=^vr,^vr,^vr"(<4 x i32> %a, <4 x i32> %a)
@@ -22,6 +27,14 @@ fixed_i32m1_t test_vr(fixed_i32m1_t a) {
2227
return ret;
2328
}
2429

30+
i32x2 test_vr2(i32x2 a) {
31+
// CHECK-LABEL: define{{.*}} @test_vr2
32+
// CHECK: %1 = tail call <2 x i32> asm sideeffect "vadd.vv $0, $1, $2", "=^vr,^vr,^vr"(<2 x i32> %0, <2 x i32> %0)
33+
i32x2 ret;
34+
asm volatile ("vadd.vv %0, %1, %2" : "=vr"(ret) : "vr"(a), "vr"(a));
35+
return ret;
36+
}
37+
2538
fixed_i8mf2_t test_vd(fixed_i8mf2_t a) {
2639
// CHECK-LABEL: define{{.*}} @test_vd
2740
// CHECK: %0 = tail call <8 x i8> asm sideeffect "vadd.vv $0, $1, $2", "=^vd,^vr,^vr"(<8 x i8> %a, <8 x i8> %a)
@@ -30,10 +43,24 @@ fixed_i8mf2_t test_vd(fixed_i8mf2_t a) {
3043
return ret;
3144
}
3245

46+
i8x4 test_vd2(i8x4 a) {
47+
// CHECK-LABEL: define{{.*}} @test_vd2
48+
// CHECK: %1 = tail call <4 x i8> asm sideeffect "vadd.vv $0, $1, $2", "=^vd,^vr,^vr"(<4 x i8> %0, <4 x i8> %0)
49+
i8x4 ret;
50+
asm volatile ("vadd.vv %0, %1, %2" : "=vd"(ret) : "vr"(a), "vr"(a));
51+
return ret;
52+
}
53+
3354
fixed_bool1_t test_vm(fixed_bool1_t a) {
3455
// CHECK-LABEL: define{{.*}} @test_vm
3556
// CHECK: %1 = tail call <16 x i8> asm sideeffect "vmand.mm $0, $1, $2", "=^vm,^vm,^vm"(<16 x i8> %a, <16 x i8> %a)
3657
fixed_bool1_t ret;
3758
asm volatile ("vmand.mm %0, %1, %2" : "=vm"(ret) : "vm"(a), "vm"(a));
3859
return ret;
3960
}
61+
62+
void test_vm2(bx2 a) {
63+
// CHECK-LABEL: define{{.*}} @test_vm2
64+
// CHECK: tail call void asm sideeffect "dummy $0", "^vm"(<16 x i1> %a1)
65+
asm volatile ("dummy %0" :: "vm"(a));
66+
}

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23440,8 +23440,8 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
2344023440

2344123441
if (VT.isFixedLengthVector() && Subtarget.useRVVForFixedLengthVectors()) {
2344223442
MVT ContainerVT = getContainerForFixedLengthVector(VT);
23443-
// VT here is coerced to vector with i8 elements, so we need to check if
23444-
// this is a M1 register here instead of checking VMV0RegClass.
23443+
// VT here might be coerced to vector with i8 elements, so we need to
23444+
// check if this is a M1 register here instead of checking VMV0RegClass.
2344523445
if (TRI->isTypeLegalForClass(RISCV::VRRegClass, ContainerVT))
2344623446
return std::make_pair(0U, &RISCV::VMV0RegClass);
2344723447
}
@@ -24425,7 +24425,10 @@ SDValue RISCVTargetLowering::joinRegisterPartsIntoValue(
2442524425
EVT::getVectorVT(Context, ValueEltVT, Count, /*IsScalable=*/true);
2442624426
Val = DAG.getNode(ISD::BITCAST, DL, SameEltTypeVT, Val);
2442724427
}
24428-
Val = DAG.getExtractSubvector(DL, ValueVT, Val, 0);
24428+
if (ValueVT.isFixedLengthVector())
24429+
Val = convertFromScalableVector(ValueVT, Val, DAG, Subtarget);
24430+
else
24431+
Val = DAG.getExtractSubvector(DL, ValueVT, Val, 0);
2442924432
return Val;
2443024433
}
2443124434
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs < %s \
3+
; RUN: | FileCheck -check-prefix=RV32I %s
4+
; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s \
5+
; RUN: | FileCheck -check-prefix=RV64I %s
6+
7+
define <1 x i8> @constraint_vr_fixed(<1 x i8> %0, <1 x i8> %1) nounwind {
8+
; RV32I-LABEL: constraint_vr_fixed:
9+
; RV32I: # %bb.0:
10+
; RV32I-NEXT: #APP
11+
; RV32I-NEXT: vadd.vv v8, v8, v9
12+
; RV32I-NEXT: #NO_APP
13+
; RV32I-NEXT: ret
14+
;
15+
; RV64I-LABEL: constraint_vr_fixed:
16+
; RV64I: # %bb.0:
17+
; RV64I-NEXT: #APP
18+
; RV64I-NEXT: vadd.vv v8, v8, v9
19+
; RV64I-NEXT: #NO_APP
20+
; RV64I-NEXT: ret
21+
%a = tail call <1 x i8> asm "vadd.vv $0, $1, $2", "=^vr,^vr,^vr"(
22+
<1 x i8> %0, <1 x i8> %1)
23+
ret <1 x i8> %a
24+
}
25+
26+
define <4 x i32> @constraint_vd_fixed(<4 x i32> %0, <4 x i32> %1) nounwind {
27+
; RV32I-LABEL: constraint_vd_fixed:
28+
; RV32I: # %bb.0:
29+
; RV32I-NEXT: #APP
30+
; RV32I-NEXT: vadd.vv v8, v8, v9
31+
; RV32I-NEXT: #NO_APP
32+
; RV32I-NEXT: ret
33+
;
34+
; RV64I-LABEL: constraint_vd_fixed:
35+
; RV64I: # %bb.0:
36+
; RV64I-NEXT: #APP
37+
; RV64I-NEXT: vadd.vv v8, v8, v9
38+
; RV64I-NEXT: #NO_APP
39+
; RV64I-NEXT: ret
40+
%a = tail call <4 x i32> asm "vadd.vv $0, $1, $2", "=^vd,^vr,^vr"(
41+
<4 x i32> %0, <4 x i32> %1)
42+
ret <4 x i32> %a
43+
}
44+
45+
define <16 x i1> @constraint_vm_fixed(<16 x i1> %0, <16 x i1> %1) nounwind {
46+
; RV32I-LABEL: constraint_vm_fixed:
47+
; RV32I: # %bb.0:
48+
; RV32I-NEXT: vsetivli zero, 1, e8, m1, ta, ma
49+
; RV32I-NEXT: vmv1r.v v9, v0
50+
; RV32I-NEXT: vmv1r.v v0, v8
51+
; RV32I-NEXT: #APP
52+
; RV32I-NEXT: vadd.vv v0, v9, v0
53+
; RV32I-NEXT: #NO_APP
54+
; RV32I-NEXT: ret
55+
;
56+
; RV64I-LABEL: constraint_vm_fixed:
57+
; RV64I: # %bb.0:
58+
; RV64I-NEXT: vsetivli zero, 1, e8, m1, ta, ma
59+
; RV64I-NEXT: vmv1r.v v9, v0
60+
; RV64I-NEXT: vmv1r.v v0, v8
61+
; RV64I-NEXT: #APP
62+
; RV64I-NEXT: vadd.vv v0, v9, v0
63+
; RV64I-NEXT: #NO_APP
64+
; RV64I-NEXT: ret
65+
%a = tail call <16 x i1> asm "vadd.vv $0, $1, $2", "=^vr,^vr,^vm"(
66+
<16 x i1> %0, <16 x i1> %1)
67+
ret <16 x i1> %a
68+
}

0 commit comments

Comments
 (0)