1// REQUIRES: amdgpu-registered-target 2// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck -enable-var-scope %s 3 4#pragma OPENCL EXTENSION cl_khr_fp64 : enable 5 6typedef unsigned long ulong; 7typedef unsigned int uint; 8typedef unsigned short ushort; 9typedef half __attribute__((ext_vector_type(2))) half2; 10typedef short __attribute__((ext_vector_type(2))) short2; 11typedef ushort __attribute__((ext_vector_type(2))) ushort2; 12typedef uint __attribute__((ext_vector_type(4))) uint4; 13 14// CHECK-LABEL: @test_div_scale_f64 15// CHECK: call { double, i1 } @llvm.amdgcn.div.scale.f64(double %a, double %b, i1 true) 16// CHECK-DAG: [[FLAG:%.+]] = extractvalue { double, i1 } %{{.+}}, 1 17// CHECK-DAG: [[VAL:%.+]] = extractvalue { double, i1 } %{{.+}}, 0 18// CHECK: [[FLAGEXT:%.+]] = zext i1 [[FLAG]] to i32 19// CHECK: store i32 [[FLAGEXT]] 20void test_div_scale_f64(global double* out, global int* flagout, double a, double b) 21{ 22 bool flag; 23 *out = __builtin_amdgcn_div_scale(a, b, true, &flag); 24 *flagout = flag; 25} 26 27// CHECK-LABEL: @test_div_scale_f32( 28// CHECK: call { float, i1 } @llvm.amdgcn.div.scale.f32(float %a, float %b, i1 true) 29// CHECK-DAG: [[FLAG:%.+]] = extractvalue { float, i1 } %{{.+}}, 1 30// CHECK-DAG: [[VAL:%.+]] = extractvalue { float, i1 } %{{.+}}, 0 31// CHECK: [[FLAGEXT:%.+]] = zext i1 [[FLAG]] to i8 32// CHECK: store i8 [[FLAGEXT]] 33void test_div_scale_f32(global float* out, global bool* flagout, float a, float b) 34{ 35 bool flag; 36 *out = __builtin_amdgcn_div_scalef(a, b, true, &flag); 37 *flagout = flag; 38} 39 40// CHECK-LABEL: @test_div_scale_f32_global_ptr( 41// CHECK: call { float, i1 } @llvm.amdgcn.div.scale.f32(float %a, float %b, i1 true) 42// CHECK-DAG: [[FLAG:%.+]] = extractvalue { float, i1 } %{{.+}}, 1 43// CHECK-DAG: [[VAL:%.+]] = extractvalue { float, i1 } %{{.+}}, 0 44// CHECK: [[FLAGEXT:%.+]] = zext i1 [[FLAG]] to i8 45// CHECK: store i8 [[FLAGEXT]] 46void test_div_scale_f32_global_ptr(global float* out, global int* flagout, float a, float b, global bool* flag) 47{ 48 *out = __builtin_amdgcn_div_scalef(a, b, true, flag); 49} 50 51// CHECK-LABEL: @test_div_scale_f32_generic_ptr( 52// CHECK: call { float, i1 } @llvm.amdgcn.div.scale.f32(float %a, float %b, i1 true) 53// CHECK-DAG: [[FLAG:%.+]] = extractvalue { float, i1 } %{{.+}}, 1 54// CHECK-DAG: [[VAL:%.+]] = extractvalue { float, i1 } %{{.+}}, 0 55// CHECK: [[FLAGEXT:%.+]] = zext i1 [[FLAG]] to i8 56// CHECK: store i8 [[FLAGEXT]] 57void test_div_scale_f32_generic_ptr(global float* out, global int* flagout, float a, float b, global bool* flag_arg) 58{ 59 generic bool* flag = flag_arg; 60 *out = __builtin_amdgcn_div_scalef(a, b, true, flag); 61} 62 63// CHECK-LABEL: @test_div_fmas_f32 64// CHECK: call float @llvm.amdgcn.div.fmas.f32 65void test_div_fmas_f32(global float* out, float a, float b, float c, int d) 66{ 67 *out = __builtin_amdgcn_div_fmasf(a, b, c, d); 68} 69 70// CHECK-LABEL: @test_div_fmas_f64 71// CHECK: call double @llvm.amdgcn.div.fmas.f64 72void test_div_fmas_f64(global double* out, double a, double b, double c, int d) 73{ 74 *out = __builtin_amdgcn_div_fmas(a, b, c, d); 75} 76 77// CHECK-LABEL: @test_div_fixup_f32 78// CHECK: call float @llvm.amdgcn.div.fixup.f32 79void test_div_fixup_f32(global float* out, float a, float b, float c) 80{ 81 *out = __builtin_amdgcn_div_fixupf(a, b, c); 82} 83 84// CHECK-LABEL: @test_div_fixup_f64 85// CHECK: call double @llvm.amdgcn.div.fixup.f64 86void test_div_fixup_f64(global double* out, double a, double b, double c) 87{ 88 *out = __builtin_amdgcn_div_fixup(a, b, c); 89} 90 91// CHECK-LABEL: @test_trig_preop_f32 92// CHECK: call float @llvm.amdgcn.trig.preop.f32 93void test_trig_preop_f32(global float* out, float a, int b) 94{ 95 *out = __builtin_amdgcn_trig_preopf(a, b); 96} 97 98// CHECK-LABEL: @test_trig_preop_f64 99// CHECK: call double @llvm.amdgcn.trig.preop.f64 100void test_trig_preop_f64(global double* out, double a, int b) 101{ 102 *out = __builtin_amdgcn_trig_preop(a, b); 103} 104 105// CHECK-LABEL: @test_rcp_f32 106// CHECK: call float @llvm.amdgcn.rcp.f32 107void test_rcp_f32(global float* out, float a) 108{ 109 *out = __builtin_amdgcn_rcpf(a); 110} 111 112// CHECK-LABEL: @test_rcp_f64 113// CHECK: call double @llvm.amdgcn.rcp.f64 114void test_rcp_f64(global double* out, double a) 115{ 116 *out = __builtin_amdgcn_rcp(a); 117} 118 119// CHECK-LABEL: @test_rsq_f32 120// CHECK: call float @llvm.amdgcn.rsq.f32 121void test_rsq_f32(global float* out, float a) 122{ 123 *out = __builtin_amdgcn_rsqf(a); 124} 125 126// CHECK-LABEL: @test_rsq_f64 127// CHECK: call double @llvm.amdgcn.rsq.f64 128void test_rsq_f64(global double* out, double a) 129{ 130 *out = __builtin_amdgcn_rsq(a); 131} 132 133// CHECK-LABEL: @test_rsq_clamp_f32 134// CHECK: call float @llvm.amdgcn.rsq.clamp.f32 135void test_rsq_clamp_f32(global float* out, float a) 136{ 137 *out = __builtin_amdgcn_rsq_clampf(a); 138} 139 140// CHECK-LABEL: @test_rsq_clamp_f64 141// CHECK: call double @llvm.amdgcn.rsq.clamp.f64 142void test_rsq_clamp_f64(global double* out, double a) 143{ 144 *out = __builtin_amdgcn_rsq_clamp(a); 145} 146 147// CHECK-LABEL: @test_sin_f32 148// CHECK: call float @llvm.amdgcn.sin.f32 149void test_sin_f32(global float* out, float a) 150{ 151 *out = __builtin_amdgcn_sinf(a); 152} 153 154// CHECK-LABEL: @test_cos_f32 155// CHECK: call float @llvm.amdgcn.cos.f32 156void test_cos_f32(global float* out, float a) 157{ 158 *out = __builtin_amdgcn_cosf(a); 159} 160 161// CHECK-LABEL: @test_log_clamp_f32 162// CHECK: call float @llvm.amdgcn.log.clamp.f32 163void test_log_clamp_f32(global float* out, float a) 164{ 165 *out = __builtin_amdgcn_log_clampf(a); 166} 167 168// CHECK-LABEL: @test_ldexp_f32 169// CHECK: call float @llvm.amdgcn.ldexp.f32 170void test_ldexp_f32(global float* out, float a, int b) 171{ 172 *out = __builtin_amdgcn_ldexpf(a, b); 173} 174 175// CHECK-LABEL: @test_ldexp_f64 176// CHECK: call double @llvm.amdgcn.ldexp.f64 177void test_ldexp_f64(global double* out, double a, int b) 178{ 179 *out = __builtin_amdgcn_ldexp(a, b); 180} 181 182// CHECK-LABEL: @test_frexp_mant_f32 183// CHECK: call float @llvm.amdgcn.frexp.mant.f32 184void test_frexp_mant_f32(global float* out, float a) 185{ 186 *out = __builtin_amdgcn_frexp_mantf(a); 187} 188 189// CHECK-LABEL: @test_frexp_mant_f64 190// CHECK: call double @llvm.amdgcn.frexp.mant.f64 191void test_frexp_mant_f64(global double* out, double a) 192{ 193 *out = __builtin_amdgcn_frexp_mant(a); 194} 195 196// CHECK-LABEL: @test_frexp_exp_f32 197// CHECK: call i32 @llvm.amdgcn.frexp.exp.i32.f32 198void test_frexp_exp_f32(global int* out, float a) 199{ 200 *out = __builtin_amdgcn_frexp_expf(a); 201} 202 203// CHECK-LABEL: @test_frexp_exp_f64 204// CHECK: call i32 @llvm.amdgcn.frexp.exp.i32.f64 205void test_frexp_exp_f64(global int* out, double a) 206{ 207 *out = __builtin_amdgcn_frexp_exp(a); 208} 209 210// CHECK-LABEL: @test_fract_f32 211// CHECK: call float @llvm.amdgcn.fract.f32 212void test_fract_f32(global int* out, float a) 213{ 214 *out = __builtin_amdgcn_fractf(a); 215} 216 217// CHECK-LABEL: @test_fract_f64 218// CHECK: call double @llvm.amdgcn.fract.f64 219void test_fract_f64(global int* out, double a) 220{ 221 *out = __builtin_amdgcn_fract(a); 222} 223 224// CHECK-LABEL: @test_lerp 225// CHECK: call i32 @llvm.amdgcn.lerp 226void test_lerp(global int* out, int a, int b, int c) 227{ 228 *out = __builtin_amdgcn_lerp(a, b, c); 229} 230 231// CHECK-LABEL: @test_sicmp_i32 232// CHECK: call i64 @llvm.amdgcn.icmp.i64.i32(i32 %a, i32 %b, i32 32) 233void test_sicmp_i32(global ulong* out, int a, int b) 234{ 235 *out = __builtin_amdgcn_sicmp(a, b, 32); 236} 237 238// CHECK-LABEL: @test_uicmp_i32 239// CHECK: call i64 @llvm.amdgcn.icmp.i64.i32(i32 %a, i32 %b, i32 32) 240void test_uicmp_i32(global ulong* out, uint a, uint b) 241{ 242 *out = __builtin_amdgcn_uicmp(a, b, 32); 243} 244 245// CHECK-LABEL: @test_sicmp_i64 246// CHECK: call i64 @llvm.amdgcn.icmp.i64.i64(i64 %a, i64 %b, i32 38) 247void test_sicmp_i64(global ulong* out, long a, long b) 248{ 249 *out = __builtin_amdgcn_sicmpl(a, b, 39-1); 250} 251 252// CHECK-LABEL: @test_uicmp_i64 253// CHECK: call i64 @llvm.amdgcn.icmp.i64.i64(i64 %a, i64 %b, i32 35) 254void test_uicmp_i64(global ulong* out, ulong a, ulong b) 255{ 256 *out = __builtin_amdgcn_uicmpl(a, b, 30+5); 257} 258 259// CHECK-LABEL: @test_ds_swizzle 260// CHECK: call i32 @llvm.amdgcn.ds.swizzle(i32 %a, i32 32) 261void test_ds_swizzle(global int* out, int a) 262{ 263 *out = __builtin_amdgcn_ds_swizzle(a, 32); 264} 265 266// CHECK-LABEL: @test_ds_permute 267// CHECK: call i32 @llvm.amdgcn.ds.permute(i32 %a, i32 %b) 268void test_ds_permute(global int* out, int a, int b) 269{ 270 out[0] = __builtin_amdgcn_ds_permute(a, b); 271} 272 273// CHECK-LABEL: @test_ds_bpermute 274// CHECK: call i32 @llvm.amdgcn.ds.bpermute(i32 %a, i32 %b) 275void test_ds_bpermute(global int* out, int a, int b) 276{ 277 *out = __builtin_amdgcn_ds_bpermute(a, b); 278} 279 280// CHECK-LABEL: @test_readfirstlane 281// CHECK: call i32 @llvm.amdgcn.readfirstlane(i32 %a) 282void test_readfirstlane(global int* out, int a) 283{ 284 *out = __builtin_amdgcn_readfirstlane(a); 285} 286 287// CHECK-LABEL: @test_readlane 288// CHECK: call i32 @llvm.amdgcn.readlane(i32 %a, i32 %b) 289void test_readlane(global int* out, int a, int b) 290{ 291 *out = __builtin_amdgcn_readlane(a, b); 292} 293 294// CHECK-LABEL: @test_fcmp_f32 295// CHECK: call i64 @llvm.amdgcn.fcmp.i64.f32(float %a, float %b, i32 5) 296void test_fcmp_f32(global ulong* out, float a, float b) 297{ 298 *out = __builtin_amdgcn_fcmpf(a, b, 5); 299} 300 301// CHECK-LABEL: @test_fcmp_f64 302// CHECK: call i64 @llvm.amdgcn.fcmp.i64.f64(double %a, double %b, i32 6) 303void test_fcmp_f64(global ulong* out, double a, double b) 304{ 305 *out = __builtin_amdgcn_fcmp(a, b, 3+3); 306} 307 308// CHECK-LABEL: @test_class_f32 309// CHECK: call i1 @llvm.amdgcn.class.f32 310void test_class_f32(global float* out, float a, int b) 311{ 312 *out = __builtin_amdgcn_classf(a, b); 313} 314 315// CHECK-LABEL: @test_class_f64 316// CHECK: call i1 @llvm.amdgcn.class.f64 317void test_class_f64(global double* out, double a, int b) 318{ 319 *out = __builtin_amdgcn_class(a, b); 320} 321 322// CHECK-LABEL: @test_buffer_wbinvl1 323// CHECK: call void @llvm.amdgcn.buffer.wbinvl1( 324void test_buffer_wbinvl1() 325{ 326 __builtin_amdgcn_buffer_wbinvl1(); 327} 328 329// CHECK-LABEL: @test_s_dcache_inv 330// CHECK: call void @llvm.amdgcn.s.dcache.inv( 331void test_s_dcache_inv() 332{ 333 __builtin_amdgcn_s_dcache_inv(); 334} 335 336// CHECK-LABEL: @test_s_waitcnt 337// CHECK: call void @llvm.amdgcn.s.waitcnt( 338void test_s_waitcnt() 339{ 340 __builtin_amdgcn_s_waitcnt(0); 341} 342 343// CHECK-LABEL: @test_s_sendmsg 344// CHECK: call void @llvm.amdgcn.s.sendmsg( 345void test_s_sendmsg() 346{ 347 __builtin_amdgcn_s_sendmsg(1, 0); 348} 349 350// CHECK-LABEL: @test_s_sendmsg_var 351// CHECK: call void @llvm.amdgcn.s.sendmsg( 352void test_s_sendmsg_var(int in) 353{ 354 __builtin_amdgcn_s_sendmsg(1, in); 355} 356 357// CHECK-LABEL: @test_s_sendmsghalt 358// CHECK: call void @llvm.amdgcn.s.sendmsghalt( 359void test_s_sendmsghalt() 360{ 361 __builtin_amdgcn_s_sendmsghalt(1, 0); 362} 363 364// CHECK-LABEL: @test_s_sendmsghalt 365// CHECK: call void @llvm.amdgcn.s.sendmsghalt( 366void test_s_sendmsghalt_var(int in) 367{ 368 __builtin_amdgcn_s_sendmsghalt(1, in); 369} 370 371// CHECK-LABEL: @test_s_barrier 372// CHECK: call void @llvm.amdgcn.s.barrier( 373void test_s_barrier() 374{ 375 __builtin_amdgcn_s_barrier(); 376} 377 378// CHECK-LABEL: @test_wave_barrier 379// CHECK: call void @llvm.amdgcn.wave.barrier( 380void test_wave_barrier() 381{ 382 __builtin_amdgcn_wave_barrier(); 383} 384 385// CHECK-LABEL: @test_s_memtime 386// CHECK: call i64 @llvm.amdgcn.s.memtime() 387void test_s_memtime(global ulong* out) 388{ 389 *out = __builtin_amdgcn_s_memtime(); 390} 391 392// CHECK-LABEL: @test_s_sleep 393// CHECK: call void @llvm.amdgcn.s.sleep(i32 1) 394// CHECK: call void @llvm.amdgcn.s.sleep(i32 15) 395void test_s_sleep() 396{ 397 __builtin_amdgcn_s_sleep(1); 398 __builtin_amdgcn_s_sleep(15); 399} 400 401// CHECK-LABEL: @test_s_incperflevel 402// CHECK: call void @llvm.amdgcn.s.incperflevel(i32 1) 403// CHECK: call void @llvm.amdgcn.s.incperflevel(i32 15) 404void test_s_incperflevel() 405{ 406 __builtin_amdgcn_s_incperflevel(1); 407 __builtin_amdgcn_s_incperflevel(15); 408} 409 410// CHECK-LABEL: @test_s_decperflevel 411// CHECK: call void @llvm.amdgcn.s.decperflevel(i32 1) 412// CHECK: call void @llvm.amdgcn.s.decperflevel(i32 15) 413void test_s_decperflevel() 414{ 415 __builtin_amdgcn_s_decperflevel(1); 416 __builtin_amdgcn_s_decperflevel(15); 417} 418 419// CHECK-LABEL: @test_cubeid( 420// CHECK: call float @llvm.amdgcn.cubeid(float %a, float %b, float %c) 421void test_cubeid(global float* out, float a, float b, float c) { 422 *out = __builtin_amdgcn_cubeid(a, b, c); 423} 424 425// CHECK-LABEL: @test_cubesc( 426// CHECK: call float @llvm.amdgcn.cubesc(float %a, float %b, float %c) 427void test_cubesc(global float* out, float a, float b, float c) { 428 *out = __builtin_amdgcn_cubesc(a, b, c); 429} 430 431// CHECK-LABEL: @test_cubetc( 432// CHECK: call float @llvm.amdgcn.cubetc(float %a, float %b, float %c) 433void test_cubetc(global float* out, float a, float b, float c) { 434 *out = __builtin_amdgcn_cubetc(a, b, c); 435} 436 437// CHECK-LABEL: @test_cubema( 438// CHECK: call float @llvm.amdgcn.cubema(float %a, float %b, float %c) 439void test_cubema(global float* out, float a, float b, float c) { 440 *out = __builtin_amdgcn_cubema(a, b, c); 441} 442 443// CHECK-LABEL: @test_read_exec( 444// CHECK: call i64 @llvm.read_register.i64(metadata ![[$EXEC:[0-9]+]]) #[[$READ_EXEC_ATTRS:[0-9]+]] 445void test_read_exec(global ulong* out) { 446 *out = __builtin_amdgcn_read_exec(); 447} 448 449// CHECK: declare i64 @llvm.read_register.i64(metadata) #[[$NOUNWIND_READONLY:[0-9]+]] 450 451// CHECK-LABEL: @test_read_exec_lo( 452// CHECK: call i32 @llvm.read_register.i32(metadata ![[$EXEC_LO:[0-9]+]]) #[[$READ_EXEC_ATTRS]] 453void test_read_exec_lo(global uint* out) { 454 *out = __builtin_amdgcn_read_exec_lo(); 455} 456 457// CHECK-LABEL: @test_read_exec_hi( 458// CHECK: call i32 @llvm.read_register.i32(metadata ![[$EXEC_HI:[0-9]+]]) #[[$READ_EXEC_ATTRS]] 459void test_read_exec_hi(global uint* out) { 460 *out = __builtin_amdgcn_read_exec_hi(); 461} 462 463// CHECK-LABEL: @test_dispatch_ptr 464// CHECK: call align 4 dereferenceable(64) i8 addrspace(4)* @llvm.amdgcn.dispatch.ptr() 465void test_dispatch_ptr(__constant unsigned char ** out) 466{ 467 *out = __builtin_amdgcn_dispatch_ptr(); 468} 469 470// CHECK-LABEL: @test_queue_ptr 471// CHECK: call i8 addrspace(4)* @llvm.amdgcn.queue.ptr() 472void test_queue_ptr(__constant unsigned char ** out) 473{ 474 *out = __builtin_amdgcn_queue_ptr(); 475} 476 477// CHECK-LABEL: @test_kernarg_segment_ptr 478// CHECK: call i8 addrspace(4)* @llvm.amdgcn.kernarg.segment.ptr() 479void test_kernarg_segment_ptr(__constant unsigned char ** out) 480{ 481 *out = __builtin_amdgcn_kernarg_segment_ptr(); 482} 483 484// CHECK-LABEL: @test_implicitarg_ptr 485// CHECK: call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr() 486void test_implicitarg_ptr(__constant unsigned char ** out) 487{ 488 *out = __builtin_amdgcn_implicitarg_ptr(); 489} 490 491// CHECK-LABEL: @test_get_group_id( 492// CHECK: tail call i32 @llvm.amdgcn.workgroup.id.x() 493// CHECK: tail call i32 @llvm.amdgcn.workgroup.id.y() 494// CHECK: tail call i32 @llvm.amdgcn.workgroup.id.z() 495void test_get_group_id(int d, global int *out) 496{ 497 switch (d) { 498 case 0: *out = __builtin_amdgcn_workgroup_id_x(); break; 499 case 1: *out = __builtin_amdgcn_workgroup_id_y(); break; 500 case 2: *out = __builtin_amdgcn_workgroup_id_z(); break; 501 default: *out = 0; 502 } 503} 504 505// CHECK-LABEL: @test_s_getreg( 506// CHECK: tail call i32 @llvm.amdgcn.s.getreg(i32 0) 507// CHECK: tail call i32 @llvm.amdgcn.s.getreg(i32 1) 508// CHECK: tail call i32 @llvm.amdgcn.s.getreg(i32 65535) 509void test_s_getreg(volatile global uint *out) 510{ 511 *out = __builtin_amdgcn_s_getreg(0); 512 *out = __builtin_amdgcn_s_getreg(1); 513 *out = __builtin_amdgcn_s_getreg(65535); 514} 515 516// CHECK-LABEL: @test_get_local_id( 517// CHECK: tail call i32 @llvm.amdgcn.workitem.id.x(), !range [[$WI_RANGE:![0-9]*]] 518// CHECK: tail call i32 @llvm.amdgcn.workitem.id.y(), !range [[$WI_RANGE]] 519// CHECK: tail call i32 @llvm.amdgcn.workitem.id.z(), !range [[$WI_RANGE]] 520void test_get_local_id(int d, global int *out) 521{ 522 switch (d) { 523 case 0: *out = __builtin_amdgcn_workitem_id_x(); break; 524 case 1: *out = __builtin_amdgcn_workitem_id_y(); break; 525 case 2: *out = __builtin_amdgcn_workitem_id_z(); break; 526 default: *out = 0; 527 } 528} 529 530// CHECK-LABEL: @test_get_workgroup_size( 531// CHECK: call align 4 dereferenceable(64) i8 addrspace(4)* @llvm.amdgcn.dispatch.ptr() 532// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i64 4 533// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 4, !range [[$WS_RANGE:![0-9]*]], !invariant.load 534// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i64 6 535// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 2, !range [[$WS_RANGE:![0-9]*]], !invariant.load 536// CHECK: getelementptr i8, i8 addrspace(4)* %{{.*}}, i64 8 537// CHECK: load i16, i16 addrspace(4)* %{{.*}}, align 4, !range [[$WS_RANGE:![0-9]*]], !invariant.load 538void test_get_workgroup_size(int d, global int *out) 539{ 540 switch (d) { 541 case 0: *out = __builtin_amdgcn_workgroup_size_x() + 1; break; 542 case 1: *out = __builtin_amdgcn_workgroup_size_y(); break; 543 case 2: *out = __builtin_amdgcn_workgroup_size_z(); break; 544 default: *out = 0; 545 } 546} 547 548// CHECK-LABEL: @test_fmed3_f32 549// CHECK: call float @llvm.amdgcn.fmed3.f32( 550void test_fmed3_f32(global float* out, float a, float b, float c) 551{ 552 *out = __builtin_amdgcn_fmed3f(a, b, c); 553} 554 555// CHECK-LABEL: @test_s_getpc 556// CHECK: call i64 @llvm.amdgcn.s.getpc() 557void test_s_getpc(global ulong* out) 558{ 559 *out = __builtin_amdgcn_s_getpc(); 560} 561 562// CHECK-LABEL: @test_ds_append_lds( 563// CHECK: call i32 @llvm.amdgcn.ds.append.p3i32(i32 addrspace(3)* %ptr, i1 false) 564kernel void test_ds_append_lds(global int* out, local int* ptr) { 565 *out = __builtin_amdgcn_ds_append(ptr); 566} 567 568// CHECK-LABEL: @test_ds_consume_lds( 569// CHECK: call i32 @llvm.amdgcn.ds.consume.p3i32(i32 addrspace(3)* %ptr, i1 false) 570kernel void test_ds_consume_lds(global int* out, local int* ptr) { 571 *out = __builtin_amdgcn_ds_consume(ptr); 572} 573 574// CHECK-LABEL: @test_gws_init( 575// CHECK: call void @llvm.amdgcn.ds.gws.init(i32 %value, i32 %id) 576kernel void test_gws_init(uint value, uint id) { 577 __builtin_amdgcn_ds_gws_init(value, id); 578} 579 580// CHECK-LABEL: @test_gws_barrier( 581// CHECK: call void @llvm.amdgcn.ds.gws.barrier(i32 %value, i32 %id) 582kernel void test_gws_barrier(uint value, uint id) { 583 __builtin_amdgcn_ds_gws_barrier(value, id); 584} 585 586// CHECK-LABEL: @test_gws_sema_v( 587// CHECK: call void @llvm.amdgcn.ds.gws.sema.v(i32 %id) 588kernel void test_gws_sema_v(uint id) { 589 __builtin_amdgcn_ds_gws_sema_v(id); 590} 591 592// CHECK-LABEL: @test_gws_sema_br( 593// CHECK: call void @llvm.amdgcn.ds.gws.sema.br(i32 %value, i32 %id) 594kernel void test_gws_sema_br(uint value, uint id) { 595 __builtin_amdgcn_ds_gws_sema_br(value, id); 596} 597 598// CHECK-LABEL: @test_gws_sema_p( 599// CHECK: call void @llvm.amdgcn.ds.gws.sema.p(i32 %id) 600kernel void test_gws_sema_p(uint id) { 601 __builtin_amdgcn_ds_gws_sema_p(id); 602} 603 604// CHECK-LABEL: @test_mbcnt_lo( 605// CHECK: call i32 @llvm.amdgcn.mbcnt.lo(i32 %src0, i32 %src1) 606kernel void test_mbcnt_lo(global uint* out, uint src0, uint src1) { 607 *out = __builtin_amdgcn_mbcnt_lo(src0, src1); 608} 609 610// CHECK-LABEL: @test_mbcnt_hi( 611// CHECK: call i32 @llvm.amdgcn.mbcnt.hi(i32 %src0, i32 %src1) 612kernel void test_mbcnt_hi(global uint* out, uint src0, uint src1) { 613 *out = __builtin_amdgcn_mbcnt_hi(src0, src1); 614} 615 616// CHECK-LABEL: @test_alignbit( 617// CHECK: tail call i32 @llvm.fshr.i32(i32 %src0, i32 %src1, i32 %src2) 618kernel void test_alignbit(global uint* out, uint src0, uint src1, uint src2) { 619 *out = __builtin_amdgcn_alignbit(src0, src1, src2); 620} 621 622// CHECK-LABEL: @test_alignbyte( 623// CHECK: tail call i32 @llvm.amdgcn.alignbyte(i32 %src0, i32 %src1, i32 %src2) 624kernel void test_alignbyte(global uint* out, uint src0, uint src1, uint src2) { 625 *out = __builtin_amdgcn_alignbyte(src0, src1, src2); 626} 627 628// CHECK-LABEL: @test_ubfe( 629// CHECK: tail call i32 @llvm.amdgcn.ubfe.i32(i32 %src0, i32 %src1, i32 %src2) 630kernel void test_ubfe(global uint* out, uint src0, uint src1, uint src2) { 631 *out = __builtin_amdgcn_ubfe(src0, src1, src2); 632} 633 634// CHECK-LABEL: @test_sbfe( 635// CHECK: tail call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 %src1, i32 %src2) 636kernel void test_sbfe(global uint* out, uint src0, uint src1, uint src2) { 637 *out = __builtin_amdgcn_sbfe(src0, src1, src2); 638} 639 640// CHECK-LABEL: @test_cvt_pkrtz( 641// CHECK: tail call <2 x half> @llvm.amdgcn.cvt.pkrtz(float %src0, float %src1) 642kernel void test_cvt_pkrtz(global half2* out, float src0, float src1) { 643 *out = __builtin_amdgcn_cvt_pkrtz(src0, src1); 644} 645 646// CHECK-LABEL: @test_cvt_pknorm_i16( 647// CHECK: tail call <2 x i16> @llvm.amdgcn.cvt.pknorm.i16(float %src0, float %src1) 648kernel void test_cvt_pknorm_i16(global short2* out, float src0, float src1) { 649 *out = __builtin_amdgcn_cvt_pknorm_i16(src0, src1); 650} 651 652// CHECK-LABEL: @test_cvt_pknorm_u16( 653// CHECK: tail call <2 x i16> @llvm.amdgcn.cvt.pknorm.u16(float %src0, float %src1) 654kernel void test_cvt_pknorm_u16(global ushort2* out, float src0, float src1) { 655 *out = __builtin_amdgcn_cvt_pknorm_u16(src0, src1); 656} 657 658// CHECK-LABEL: @test_cvt_pk_i16( 659// CHECK: tail call <2 x i16> @llvm.amdgcn.cvt.pk.i16(i32 %src0, i32 %src1) 660kernel void test_cvt_pk_i16(global short2* out, int src0, int src1) { 661 *out = __builtin_amdgcn_cvt_pk_i16(src0, src1); 662} 663 664// CHECK-LABEL: @test_cvt_pk_u16( 665// CHECK: tail call <2 x i16> @llvm.amdgcn.cvt.pk.u16(i32 %src0, i32 %src1) 666kernel void test_cvt_pk_u16(global ushort2* out, uint src0, uint src1) { 667 *out = __builtin_amdgcn_cvt_pk_u16(src0, src1); 668} 669 670// CHECK-LABEL: @test_cvt_pk_u8_f32 671// CHECK: tail call i32 @llvm.amdgcn.cvt.pk.u8.f32(float %src0, i32 %src1, i32 %src2) 672kernel void test_cvt_pk_u8_f32(global uint* out, float src0, uint src1, uint src2) { 673 *out = __builtin_amdgcn_cvt_pk_u8_f32(src0, src1, src2); 674} 675 676// CHECK-LABEL: @test_sad_u8( 677// CHECK: tail call i32 @llvm.amdgcn.sad.u8(i32 %src0, i32 %src1, i32 %src2) 678kernel void test_sad_u8(global uint* out, uint src0, uint src1, uint src2) { 679 *out = __builtin_amdgcn_sad_u8(src0, src1, src2); 680} 681 682// CHECK-LABEL: test_msad_u8( 683// CHECK: call i32 @llvm.amdgcn.msad.u8(i32 %src0, i32 %src1, i32 %src2) 684kernel void test_msad_u8(global uint* out, uint src0, uint src1, uint src2) { 685 *out = __builtin_amdgcn_msad_u8(src0, src1, src2); 686} 687 688// CHECK-LABEL: test_sad_hi_u8( 689// CHECK: call i32 @llvm.amdgcn.sad.hi.u8(i32 %src0, i32 %src1, i32 %src2) 690kernel void test_sad_hi_u8(global uint* out, uint src0, uint src1, uint src2) { 691 *out = __builtin_amdgcn_sad_hi_u8(src0, src1, src2); 692} 693 694// CHECK-LABEL: @test_sad_u16( 695// CHECK: call i32 @llvm.amdgcn.sad.u16(i32 %src0, i32 %src1, i32 %src2) 696kernel void test_sad_u16(global uint* out, uint src0, uint src1, uint src2) { 697 *out = __builtin_amdgcn_sad_u16(src0, src1, src2); 698} 699 700// CHECK-LABEL: @test_qsad_pk_u16_u8( 701// CHECK: call i64 @llvm.amdgcn.qsad.pk.u16.u8(i64 %src0, i32 %src1, i64 %src2) 702kernel void test_qsad_pk_u16_u8(global ulong* out, ulong src0, uint src1, ulong src2) { 703 *out = __builtin_amdgcn_qsad_pk_u16_u8(src0, src1, src2); 704} 705 706// CHECK-LABEL: @test_mqsad_pk_u16_u8( 707// CHECK: call i64 @llvm.amdgcn.mqsad.pk.u16.u8(i64 %src0, i32 %src1, i64 %src2) 708kernel void test_mqsad_pk_u16_u8(global ulong* out, ulong src0, uint src1, ulong src2) { 709 *out = __builtin_amdgcn_mqsad_pk_u16_u8(src0, src1, src2); 710} 711 712// CHECK-LABEL: test_mqsad_u32_u8( 713// CHECK: call <4 x i32> @llvm.amdgcn.mqsad.u32.u8(i64 %src0, i32 %src1, <4 x i32> %src2) 714kernel void test_mqsad_u32_u8(global uint4* out, ulong src0, uint src1, uint4 src2) { 715 *out = __builtin_amdgcn_mqsad_u32_u8(src0, src1, src2); 716} 717 718// CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024} 719// CHECK-DAG: [[$WS_RANGE]] = !{i16 1, i16 1025} 720// CHECK-DAG: attributes #[[$NOUNWIND_READONLY:[0-9]+]] = { nounwind readonly } 721// CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent } 722// CHECK-DAG: ![[$EXEC]] = !{!"exec"} 723// CHECK-DAG: ![[$EXEC_LO]] = !{!"exec_lo"} 724// CHECK-DAG: ![[$EXEC_HI]] = !{!"exec_hi"} 725