Skip to content

Commit 9005059

Browse files
authored
[RISCV] Check the VT for R and cR inline asm constraints is 2*xlen. (#137749)
Fixes #137726.
1 parent cf7301a commit 9005059

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22532,7 +22532,10 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
2253222532
}
2253322533
break;
2253422534
case 'R':
22535-
return std::make_pair(0U, &RISCV::GPRPairNoX0RegClass);
22535+
if (((VT == MVT::i64 || VT == MVT::f64) && !Subtarget.is64Bit()) ||
22536+
(VT == MVT::i128 && Subtarget.is64Bit()))
22537+
return std::make_pair(0U, &RISCV::GPRPairNoX0RegClass);
22538+
break;
2253622539
default:
2253722540
break;
2253822541
}
@@ -22574,7 +22577,9 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
2257422577
if (!VT.isVector())
2257522578
return std::make_pair(0U, &RISCV::GPRCRegClass);
2257622579
} else if (Constraint == "cR") {
22577-
return std::make_pair(0U, &RISCV::GPRPairCRegClass);
22580+
if (((VT == MVT::i64 || VT == MVT::f64) && !Subtarget.is64Bit()) ||
22581+
(VT == MVT::i128 && Subtarget.is64Bit()))
22582+
return std::make_pair(0U, &RISCV::GPRPairCRegClass);
2257822583
} else if (Constraint == "cf") {
2257922584
if (VT == MVT::f16) {
2258022585
if (Subtarget.hasStdExtZfhmin())

llvm/test/CodeGen/RISCV/inline-asm-invalid.ll

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: not llc -mtriple=riscv32 < %s 2>&1 | FileCheck %s
2-
; RUN: not llc -mtriple=riscv64 < %s 2>&1 | FileCheck %s
1+
; RUN: not llc -mtriple=riscv32 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK32
2+
; RUN: not llc -mtriple=riscv64 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK64
33

44
define void @constraint_I() {
55
; CHECK: error: value out of range for constraint 'I'
@@ -62,3 +62,51 @@ define void @constraint_cr_scalable_vec() nounwind {
6262
tail call void asm "add a0, a0, $0", "^cr"(<vscale x 4 x i32> zeroinitializer)
6363
ret void
6464
}
65+
66+
define void @constraint_R_i32() nounwind {
67+
; CHECK32: error: couldn't allocate input reg for constraint 'R'
68+
tail call void asm "add a0, a0, $0", "R"(i32 zeroinitializer)
69+
ret void
70+
}
71+
72+
define void @constraint_R_i64() nounwind {
73+
; CHECK64: error: couldn't allocate input reg for constraint 'R'
74+
tail call void asm "add a0, a0, $0", "R"(i64 zeroinitializer)
75+
ret void
76+
}
77+
78+
define void @constraint_R_i128() nounwind {
79+
; CHECK32: error: couldn't allocate input reg for constraint 'R'
80+
tail call void asm "add a0, a0, $0", "R"(i128 zeroinitializer)
81+
ret void
82+
}
83+
84+
define void @constraint_R_i256() nounwind {
85+
; CHECK: error: couldn't allocate input reg for constraint 'R'
86+
tail call void asm "add a0, a0, $0", "R"(i256 zeroinitializer)
87+
ret void
88+
}
89+
90+
define void @constraint_cR_i32() nounwind {
91+
; CHECK32: error: couldn't allocate input reg for constraint 'cR'
92+
tail call void asm "add a0, a0, $0", "^cR"(i32 zeroinitializer)
93+
ret void
94+
}
95+
96+
define void @constraint_cR_i64() nounwind {
97+
; CHECK64: error: couldn't allocate input reg for constraint 'cR'
98+
tail call void asm "add a0, a0, $0", "^cR"(i64 zeroinitializer)
99+
ret void
100+
}
101+
102+
define void @constraint_cR_i128() nounwind {
103+
; CHECK32: error: couldn't allocate input reg for constraint 'cR'
104+
tail call void asm "add a0, a0, $0", "^cR"(i128 zeroinitializer)
105+
ret void
106+
}
107+
108+
define void @constraint_cR_i256() nounwind {
109+
; CHECK: error: couldn't allocate input reg for constraint 'cR'
110+
tail call void asm "add a0, a0, $0", "^cR"(i256 zeroinitializer)
111+
ret void
112+
}

0 commit comments

Comments
 (0)