Skip to content

Commit 6981d5a

Browse files
committed
clang/AMDGPU: Emit grid size builtins with range metadata
These cannot be 0.
1 parent a63f915 commit 6981d5a

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
@@ -18671,6 +18671,12 @@ Value *EmitAMDGPUGridSize(CodeGenFunction &CGF, unsigned Index) {
1867118671
auto *GEP = CGF.Builder.CreateGEP(CGF.Int8Ty, DP, Offset);
1867218672
auto *LD = CGF.Builder.CreateLoad(
1867318673
Address(GEP, CGF.Int32Ty, CharUnits::fromQuantity(4)));
18674+
18675+
llvm::MDBuilder MDB(CGF.getLLVMContext());
18676+
18677+
// Known non-zero.
18678+
LD->setMetadata(llvm::LLVMContext::MD_range,
18679+
MDB.createRange(APInt(32, 1), APInt::getZero(32)));
1867418680
LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
1867518681
llvm::MDNode::get(CGF.getLLVMContext(), {}));
1867618682
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 %{{.+}}
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)