// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals smart
// REQUIRES: amdgpu-registered-target
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950         -emit-llvm -o - %s | FileCheck %s -check-prefixes=GFX,GFX950
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx9-4-generic -emit-llvm -o - %s | FileCheck %s -check-prefixes=GFX,GFX9_4_GENERIC

typedef __attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int v4u32;
typedef v4u32 __global *global_ptr_to_v4u32;

//------------------------------------------------------------------------------
// Store
//------------------------------------------------------------------------------
// GFX-LABEL: @test_amdgcn_global_store_b128_00(
// GFX-NEXT:  entry:
// GFX-NEXT:    tail call void @llvm.amdgcn.global.store.b128(ptr addrspace(1) [[PTR:%.*]], <4 x i32> [[DATA:%.*]], metadata [[META4:![0-9]+]])
// GFX-NEXT:    ret void
//
void test_amdgcn_global_store_b128_00(global_ptr_to_v4u32 ptr, v4u32 data) {
  __builtin_amdgcn_global_store_b128(ptr, data, "wavefront");
}

// GFX-LABEL: @test_amdgcn_global_store_b128_01(
// GFX-NEXT:  entry:
// GFX-NEXT:    tail call void @llvm.amdgcn.global.store.b128(ptr addrspace(1) [[PTR:%.*]], <4 x i32> [[DATA:%.*]], metadata [[META5:![0-9]+]])
// GFX-NEXT:    ret void
//
void test_amdgcn_global_store_b128_01(global_ptr_to_v4u32 ptr, v4u32 data) {
  __builtin_amdgcn_global_store_b128(ptr, data, "workgroup");
}

// GFX-LABEL: @test_amdgcn_global_store_b128_10(
// GFX-NEXT:  entry:
// GFX-NEXT:    tail call void @llvm.amdgcn.global.store.b128(ptr addrspace(1) [[PTR:%.*]], <4 x i32> [[DATA:%.*]], metadata [[META6:![0-9]+]])
// GFX-NEXT:    ret void
//
void test_amdgcn_global_store_b128_10(global_ptr_to_v4u32 ptr, v4u32 data) {
  __builtin_amdgcn_global_store_b128(ptr, data, "agent");
}

// GFX-LABEL: @test_amdgcn_global_store_b128_11(
// GFX-NEXT:  entry:
// GFX-NEXT:    tail call void @llvm.amdgcn.global.store.b128(ptr addrspace(1) [[PTR:%.*]], <4 x i32> [[DATA:%.*]], metadata [[META7:![0-9]+]])
// GFX-NEXT:    ret void
//
void test_amdgcn_global_store_b128_11(global_ptr_to_v4u32 ptr, v4u32 data) {
  __builtin_amdgcn_global_store_b128(ptr, data, "");
}

//------------------------------------------------------------------------------
// Load
//------------------------------------------------------------------------------
// GFX-LABEL: @test_amdgcn_global_load_b128_00(
// GFX-NEXT:  entry:
// GFX-NEXT:    [[TMP0:%.*]] = tail call <4 x i32> @llvm.amdgcn.global.load.b128(ptr addrspace(1) [[PTR:%.*]], metadata [[META4]])
// GFX-NEXT:    ret <4 x i32> [[TMP0]]
//
v4u32 test_amdgcn_global_load_b128_00(global_ptr_to_v4u32 ptr) {
  return __builtin_amdgcn_global_load_b128(ptr, "wavefront");
}

// GFX-LABEL: @test_amdgcn_global_load_b128_01(
// GFX-NEXT:  entry:
// GFX-NEXT:    [[TMP0:%.*]] = tail call <4 x i32> @llvm.amdgcn.global.load.b128(ptr addrspace(1) [[PTR:%.*]], metadata [[META5]])
// GFX-NEXT:    ret <4 x i32> [[TMP0]]
//
v4u32 test_amdgcn_global_load_b128_01(global_ptr_to_v4u32 ptr) {
  return __builtin_amdgcn_global_load_b128(ptr, "workgroup");
}

// GFX-LABEL: @test_amdgcn_global_load_b128_10(
// GFX-NEXT:  entry:
// GFX-NEXT:    [[TMP0:%.*]] = tail call <4 x i32> @llvm.amdgcn.global.load.b128(ptr addrspace(1) [[PTR:%.*]], metadata [[META6]])
// GFX-NEXT:    ret <4 x i32> [[TMP0]]
//
v4u32 test_amdgcn_global_load_b128_10(global_ptr_to_v4u32 ptr) {
  return __builtin_amdgcn_global_load_b128(ptr, "agent");
}

// GFX-LABEL: @test_amdgcn_global_load_b128_11(
// GFX-NEXT:  entry:
// GFX-NEXT:    [[TMP0:%.*]] = tail call <4 x i32> @llvm.amdgcn.global.load.b128(ptr addrspace(1) [[PTR:%.*]], metadata [[META7]])
// GFX-NEXT:    ret <4 x i32> [[TMP0]]
//
v4u32 test_amdgcn_global_load_b128_11(global_ptr_to_v4u32 ptr) {
  return __builtin_amdgcn_global_load_b128(ptr, "");
}
//.
// GFX950: [[META4]] = !{!"wavefront"}
// GFX950: [[META5]] = !{!"workgroup"}
// GFX950: [[META6]] = !{!"agent"}
// GFX950: [[META7]] = !{!""}
//.
// GFX9_4_GENERIC: [[META4]] = !{!"wavefront"}
// GFX9_4_GENERIC: [[META5]] = !{!"workgroup"}
// GFX9_4_GENERIC: [[META6]] = !{!"agent"}
// GFX9_4_GENERIC: [[META7]] = !{!""}
//.
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
// GFX950: {{.*}}
// GFX9_4_GENERIC: {{.*}}
