Skip to content

Commit 2df05cd

Browse files
committed
[RISCV] Support overloaded version ntlh intrinsic function
Here is the proposal riscv-non-isa/riscv-c-api-doc#47. The version that omit the domain argument imply domain=__RISCV_NTLH_ALL. ``` type __riscv_ntl_load (type *ptr); void __riscv_ntl_store (type *ptr, type val); ``` Reviewed By: kito-cheng, craig.topper Differential Revision: https://reviews.llvm.org/D156221
1 parent b80ff2f commit 2df05cd

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20298,11 +20298,13 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
2029820298
// Zihintntl
2029920299
case RISCV::BI__builtin_riscv_ntl_load: {
2030020300
llvm::Type *ResTy = ConvertType(E->getType());
20301-
ConstantInt *Mode = cast<ConstantInt>(Ops[1]);
20301+
unsigned DomainVal = 5; // Default __RISCV_NTLH_ALL
20302+
if (Ops.size() == 2)
20303+
DomainVal = cast<ConstantInt>(Ops[1])->getZExtValue();
2030220304

2030320305
llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
2030420306
getLLVMContext(),
20305-
llvm::ConstantAsMetadata::get(Builder.getInt32(Mode->getZExtValue())));
20307+
llvm::ConstantAsMetadata::get(Builder.getInt32(DomainVal)));
2030620308
llvm::MDNode *NontemporalNode = llvm::MDNode::get(
2030720309
getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
2030820310

@@ -20324,11 +20326,13 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
2032420326
return Load;
2032520327
}
2032620328
case RISCV::BI__builtin_riscv_ntl_store: {
20327-
ConstantInt *Mode = cast<ConstantInt>(Ops[2]);
20329+
unsigned DomainVal = 5; // Default __RISCV_NTLH_ALL
20330+
if (Ops.size() == 3)
20331+
DomainVal = cast<ConstantInt>(Ops[2])->getZExtValue();
2032820332

2032920333
llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
2033020334
getLLVMContext(),
20331-
llvm::ConstantAsMetadata::get(Builder.getInt32(Mode->getZExtValue())));
20335+
llvm::ConstantAsMetadata::get(Builder.getInt32(DomainVal)));
2033220336
llvm::MDNode *NontemporalNode = llvm::MDNode::get(
2033320337
getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1)));
2033420338

clang/lib/Headers/riscv_ntlh.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ enum {
2121
__RISCV_NTLH_ALL
2222
};
2323

24-
#define __riscv_ntl_load(PTR, DOMAIN) __builtin_riscv_ntl_load((PTR), (DOMAIN))
25-
#define __riscv_ntl_store(PTR, VAL, DOMAIN) \
26-
__builtin_riscv_ntl_store((PTR), (VAL), (DOMAIN))
27-
28-
#endif
24+
#define __riscv_ntl_load __builtin_riscv_ntl_load
25+
#define __riscv_ntl_store __builtin_riscv_ntl_store
26+
#endif

clang/lib/Sema/SemaChecking.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,12 +5287,16 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo &TI,
52875287
bool IsStore = BuiltinID == RISCV::BI__builtin_riscv_ntl_store;
52885288
unsigned NumArgs = IsStore ? 3 : 2;
52895289

5290-
if (checkArgCount(*this, TheCall, NumArgs))
5290+
if (checkArgCountAtLeast(*this, TheCall, NumArgs - 1))
5291+
return true;
5292+
5293+
if (checkArgCountAtMost(*this, TheCall, NumArgs))
52915294
return true;
52925295

52935296
// Domain value should be compile-time constant.
52945297
// 2 <= domain <= 5
5295-
if (SemaBuiltinConstantArgRange(TheCall, NumArgs - 1, 2, 5))
5298+
if (TheCall->getNumArgs() == NumArgs &&
5299+
SemaBuiltinConstantArgRange(TheCall, NumArgs - 1, 2, 5))
52965300
return true;
52975301

52985302
Expr *PointerArg = TheCall->getArg(0);

clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ void ntl_all_sizes() { // CHECK-LABEL: ntl
100100
*scvs1 = __riscv_ntl_load(scvs2, __RISCV_NTLH_ALL); // CHECK: load <vscale x 4 x i16>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
101101
*scvc1 = __riscv_ntl_load(scvc2, __RISCV_NTLH_ALL); // CHECK: load <vscale x 8 x i8>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
102102

103+
uc = __riscv_ntl_load(&sc); // CHECK: load i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
104+
sc = __riscv_ntl_load(&uc); // CHECK: load i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
105+
us = __riscv_ntl_load(&ss); // CHECK: load i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
106+
ss = __riscv_ntl_load(&us); // CHECK: load i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
107+
ui = __riscv_ntl_load(&si); // CHECK: load i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
108+
si = __riscv_ntl_load(&ui); // CHECK: load i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
109+
ull = __riscv_ntl_load(&sll); // CHECK: load i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
110+
sll = __riscv_ntl_load(&ull); // CHECK: load i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
111+
h1 = __riscv_ntl_load(&h2); // CHECK: load half{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
112+
f1 = __riscv_ntl_load(&f2); // CHECK: load float{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
113+
d1 = __riscv_ntl_load(&d2); // CHECK: load double{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
114+
v4si1 = __riscv_ntl_load(&v4si2); // CHECK: load <4 x i32>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
115+
v8ss1 = __riscv_ntl_load(&v8ss2); // CHECK: load <8 x i16>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
116+
v16sc1 = __riscv_ntl_load(&v16sc2); // CHECK: load <16 x i8>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
117+
*scvi1 = __riscv_ntl_load(scvi2); // CHECK: load <vscale x 2 x i32>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
118+
*scvs1 = __riscv_ntl_load(scvs2); // CHECK: load <vscale x 4 x i16>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
119+
*scvc1 = __riscv_ntl_load(scvc2); // CHECK: load <vscale x 8 x i8>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
120+
103121
__riscv_ntl_store(&uc, 1, __RISCV_NTLH_INNERMOST_PRIVATE); // CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !5
104122
__riscv_ntl_store(&sc, 1, __RISCV_NTLH_INNERMOST_PRIVATE); // CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !5
105123
__riscv_ntl_store(&us, 1, __RISCV_NTLH_INNERMOST_PRIVATE); // CHECK: store i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !5
@@ -172,11 +190,28 @@ void ntl_all_sizes() { // CHECK-LABEL: ntl
172190
__riscv_ntl_store(scvs2, *scvs1, __RISCV_NTLH_ALL); // CHECK: store <vscale x 4 x i16>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
173191
__riscv_ntl_store(scvc2, *scvc1, __RISCV_NTLH_ALL); // CHECK: store <vscale x 8 x i8>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
174192

193+
__riscv_ntl_store(&uc, 1); // CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
194+
__riscv_ntl_store(&sc, 1); // CHECK: store i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !8
195+
__riscv_ntl_store(&us, 1); // CHECK: store i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
196+
__riscv_ntl_store(&ss, 1); // CHECK: store i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
197+
__riscv_ntl_store(&ui, 1); // CHECK: store i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
198+
__riscv_ntl_store(&si, 1); // CHECK: store i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
199+
__riscv_ntl_store(&ull, 1); // CHECK: store i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
200+
__riscv_ntl_store(&sll, 1); // CHECK: store i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
201+
__riscv_ntl_store(&h1, 1.0); // CHECK: store half{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !8
202+
__riscv_ntl_store(&f1, 1.0); // CHECK: store float{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !8
203+
__riscv_ntl_store(&d1, 1.0); // CHECK: store double{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
204+
__riscv_ntl_store(&v4si1, v4si2); // CHECK: store <4 x i32>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
205+
__riscv_ntl_store(&v8ss1, v8ss2); // CHECK: store <8 x i16>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
206+
__riscv_ntl_store(&v16sc1, v16sc2); // CHECK: store <16 x i8>{{.*}}align 16, !nontemporal !4, !riscv-nontemporal-domain !8
207+
__riscv_ntl_store(scvi2, *scvi1); // CHECK: store <vscale x 2 x i32>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
208+
__riscv_ntl_store(scvs2, *scvs1); // CHECK: store <vscale x 4 x i16>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
209+
__riscv_ntl_store(scvc2, *scvc1); // CHECK: store <vscale x 8 x i8>{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !8
175210
}
176211
// clang-format on
177212

178213
// CHECK: !4 = !{i32 1}
179214
// CHECK: !5 = !{i32 2}
180215
// CHECK: !6 = !{i32 3}
181216
// CHECK: !7 = !{i32 4}
182-
// CHECK: !8 = !{i32 5}
217+
// CHECK: !8 = !{i32 5}

0 commit comments

Comments
 (0)