Skip to content

Commit 708215d

Browse files
committed
clang/AMDGPU: Emit grid size builtins with range metadata
These cannot be 0.
1 parent 297173f commit 708215d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18538,6 +18538,12 @@ Value *EmitAMDGPUGridSize(CodeGenFunction &CGF, unsigned Index) {
1853818538
auto *GEP = CGF.Builder.CreateGEP(CGF.Int8Ty, DP, Offset);
1853918539
auto *LD = CGF.Builder.CreateLoad(
1854018540
Address(GEP, CGF.Int32Ty, CharUnits::fromQuantity(4)));
18541+
18542+
llvm::MDBuilder MDB(CGF.getLLVMContext());
18543+
18544+
// Known non-zero.
18545+
LD->setMetadata(llvm::LLVMContext::MD_range,
18546+
MDB.createRange(APInt(32, 1), APInt::getZero(32)));
1854118547
LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
1854218548
llvm::MDNode::get(CGF.getLLVMContext(), std::nullopt));
1854318549
return LD;

clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ void test_get_workgroup_size(int d, global int *out)
639639
// CHECK-LABEL: @test_get_grid_size(
640640
// CHECK: {{.*}}call align 4 dereferenceable(64){{.*}} ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
641641
// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 %.sink
642-
// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load
642+
// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !range [[$GRID_RANGE:![0-9]+]], !invariant.load
643643
void test_get_grid_size(int d, global int *out)
644644
{
645645
switch (d) {
@@ -896,5 +896,6 @@ void test_set_fpenv(unsigned long env) {
896896
__builtin_amdgcn_set_fpenv(env);
897897
}
898898

899+
// CHECK-DAG: [[$GRID_RANGE]] = !{i32 1, i32 0}
899900
// CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025}
900901
// CHECK-DAG: attributes #[[$NOUNWIND_READONLY]] = { convergent mustprogress nocallback nofree nounwind willreturn memory(none) }

0 commit comments

Comments
 (0)