Skip to content

Commit a23d65a

Browse files
committed
[RISCV] Add missing Xsfvcp extension check in clang sema
Differential Revision: https://reviews.llvm.org/D157474
1 parent 555e030 commit a23d65a

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

clang/lib/Sema/SemaRISCVVectorLookup.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,20 @@ class RISCVIntrinsicManagerImpl : public sema::RISCVIntrinsicManager {
202202
void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
203203
ArrayRef<RVVIntrinsicRecord> Recs, IntrinsicKind K) {
204204
const TargetInfo &TI = Context.getTargetInfo();
205-
bool HasRV64 = TI.hasFeature("64bit");
205+
static const std::pair<const char *, uint8_t> FeatureCheckList[] = {
206+
{"64bit", RVV_REQ_RV64},
207+
{"xsfvcp", RVV_REQ_Xsfvcp}};
208+
206209
// Construction of RVVIntrinsicRecords need to sync with createRVVIntrinsics
207210
// in RISCVVEmitter.cpp.
208211
for (auto &Record : Recs) {
212+
// Check requirements.
213+
if (llvm::any_of(FeatureCheckList, [&](const auto &Item) {
214+
return (Record.RequiredExtensions & Item.second) == Item.second &&
215+
!TI.hasFeature(Item.first);
216+
}))
217+
continue;
218+
209219
// Create Intrinsics for each type and LMUL.
210220
BasicType BaseType = BasicType::Unknown;
211221
ArrayRef<PrototypeDescriptor> BasicProtoSeq =
@@ -251,11 +261,6 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
251261
if ((BaseTypeI & Record.TypeRangeMask) != BaseTypeI)
252262
continue;
253263

254-
// Check requirement.
255-
if (((Record.RequiredExtensions & RVV_REQ_RV64) == RVV_REQ_RV64) &&
256-
!HasRV64)
257-
continue;
258-
259264
// Expanded with different LMUL.
260265
for (int Log2LMUL = -3; Log2LMUL <= 3; Log2LMUL++) {
261266
if (!(Record.Log2LMULMask & (1 << (Log2LMUL + 3))))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// REQUIRES: riscv-registered-target
2+
// RUN: %clang_cc1 -triple riscv32 -target-feature +v %s -fsyntax-only -verify
3+
4+
#include <riscv_vector.h>
5+
#include <sifive_vector.h>
6+
7+
vint8m1_t test_vloxei64_v_i8m1(const int8_t *base, vuint64m8_t bindex, size_t vl) {
8+
return __riscv_vloxei64(base, bindex, vl); // expected-error {{call to undeclared function '__riscv_vloxei64'}} expected-error {{returning 'int' from a function with incompatible result type 'vint8m1_t'}}
9+
}
10+
11+
void test_vsoxei64_v_i8m1(int8_t *base, vuint64m8_t bindex, vint8m1_t value, size_t vl) {
12+
__riscv_vsoxei64(base, bindex, value, vl); // expected-error {{call to undeclared function '__riscv_vsoxei64'}}
13+
}
14+
15+
void test_xsfvcp_sf_vc_x_se_u64m1(uint64_t rs1, size_t vl) {
16+
__riscv_sf_vc_x_se_u64m1(1, 1, 1, rs1, vl); // expected-error {{call to undeclared function '__riscv_sf_vc_x_se_u64m1'}}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// REQUIRES: riscv-registered-target
2+
// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +xsfvcp %s -fsyntax-only -verify
3+
4+
// expected-no-diagnostics
5+
6+
#include <riscv_vector.h>
7+
#include <sifive_vector.h>
8+
9+
vint8m1_t test_vloxei64_v_i8m1(const int8_t *base, vuint64m8_t bindex, size_t vl) {
10+
return __riscv_vloxei64(base, bindex, vl);
11+
}
12+
13+
void test_vsoxei64_v_i8m1(int8_t *base, vuint64m8_t bindex, vint8m1_t value, size_t vl) {
14+
__riscv_vsoxei64(base, bindex, value, vl);
15+
}
16+
17+
void test_sf_vc_x_se_u64m1(uint64_t rs1, size_t vl) {
18+
__riscv_sf_vc_x_se_u64m1(1, 1, 1, rs1, vl);
19+
}

0 commit comments

Comments
 (0)