261 lines · plain
1// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \2// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \3// RUN: -fnative-int16-type -emit-llvm -O1 -o - | FileCheck %s -DTARGET=dx \4// RUN: --check-prefixes=CHECK,DXCHECK5// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \6// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \7// RUN: -fnative-int16-type -emit-llvm -O1 -o - | FileCheck %s -DTARGET=spv8 9#ifdef __HLSL_ENABLE_16_BIT10// CHECK-LABEL: test_firstbithigh_ushort11// CHECK: [[FBH:%.*]] = tail call {{.*}}i32 @llvm.[[TARGET]].firstbituhigh.i1612// DXCHECK-NEXT: [[SUB:%.*]] = sub i32 15, [[FBH]]13// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 [[FBH]], -114// DXCHECK-NEXT: select i1 %cmp.i, i32 -1, i32 [[SUB]]15// CHECK-NEXT: ret i3216uint test_firstbithigh_ushort(uint16_t p0) {17 return firstbithigh(p0);18}19 20// CHECK-LABEL: test_firstbithigh_ushort221// CHECK: [[FBH:%.*]] = tail call {{.*}}<2 x i32> @llvm.[[TARGET]].firstbituhigh.v2i1622// DXCHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 15), [[FBH]]23// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> [[FBH]], splat (i32 -1)24// DXCHECK-NEXT: select <2 x i1> %cmp.i, <2 x i32> splat (i32 -1), <2 x i32> [[SUB]]25// CHECK-NEXT: ret <2 x i32>26uint2 test_firstbithigh_ushort2(uint16_t2 p0) {27 return firstbithigh(p0);28}29 30// CHECK-LABEL: test_firstbithigh_ushort331// CHECK: [[FBH:%.*]] = tail call {{.*}}<3 x i32> @llvm.[[TARGET]].firstbituhigh.v3i1632// DXCHECK-NEXT: [[SUB:%.*]] = sub <3 x i32> splat (i32 15), [[FBH]]33// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <3 x i32> [[FBH]], splat (i32 -1)34// DXCHECK-NEXT: select <3 x i1> %cmp.i, <3 x i32> splat (i32 -1), <3 x i32> [[SUB]]35// CHECK-NEXT: ret <3 x i32>36uint3 test_firstbithigh_ushort3(uint16_t3 p0) {37 return firstbithigh(p0);38}39 40// CHECK-LABEL: test_firstbithigh_ushort441// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbituhigh.v4i1642// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 15), [[FBH]]43// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)44// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]45// CHECK-NEXT: ret <4 x i32>46uint4 test_firstbithigh_ushort4(uint16_t4 p0) {47 return firstbithigh(p0);48}49 50// CHECK-LABEL: test_firstbithigh_short51// CHECK: [[FBH:%.*]] = tail call {{.*}}i32 @llvm.[[TARGET]].firstbitshigh.i1652// DXCHECK-NEXT: [[SUB:%.*]] = sub i32 15, [[FBH]]53// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 [[FBH]], -154// DXCHECK-NEXT: select i1 %cmp.i, i32 -1, i32 [[SUB]]55// CHECK-NEXT: ret i3256uint test_firstbithigh_short(int16_t p0) {57 return firstbithigh(p0);58}59 60// CHECK-LABEL: test_firstbithigh_short261// CHECK: [[FBH:%.*]] = tail call {{.*}}<2 x i32> @llvm.[[TARGET]].firstbitshigh.v2i1662// DXCHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 15), [[FBH]]63// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> [[FBH]], splat (i32 -1)64// DXCHECK-NEXT: select <2 x i1> %cmp.i, <2 x i32> splat (i32 -1), <2 x i32> [[SUB]]65// CHECK-NEXT: ret <2 x i32>66uint2 test_firstbithigh_short2(int16_t2 p0) {67 return firstbithigh(p0);68}69 70// CHECK-LABEL: test_firstbithigh_short371// CHECK: [[FBH:%.*]] = tail call {{.*}}<3 x i32> @llvm.[[TARGET]].firstbitshigh.v3i1672// DXCHECK-NEXT: [[SUB:%.*]] = sub <3 x i32> splat (i32 15), [[FBH]]73// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <3 x i32> [[FBH]], splat (i32 -1)74// DXCHECK-NEXT: select <3 x i1> %cmp.i, <3 x i32> splat (i32 -1), <3 x i32> [[SUB]]75// CHECK-NEXT: ret <3 x i32>76uint3 test_firstbithigh_short3(int16_t3 p0) {77 return firstbithigh(p0);78}79 80// CHECK-LABEL: test_firstbithigh_short481// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbitshigh.v4i1682// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 15), [[FBH]]83// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)84// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]85// CHECK-NEXT: ret <4 x i32>86uint4 test_firstbithigh_short4(int16_t4 p0) {87 return firstbithigh(p0);88}89#endif // __HLSL_ENABLE_16_BIT90 91// CHECK-LABEL: test_firstbithigh_uint92// CHECK: [[FBH:%.*]] = tail call {{.*}}i32 @llvm.[[TARGET]].firstbituhigh.i3293// DXCHECK-NEXT: [[SUB:%.*]] = sub i32 31, [[FBH]]94// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 [[FBH]], -195// DXCHECK-NEXT: select i1 %cmp.i, i32 -1, i32 [[SUB]]96// CHECK-NEXT: ret i3297uint test_firstbithigh_uint(uint p0) {98 return firstbithigh(p0);99}100 101// CHECK-LABEL: test_firstbithigh_uint2102// CHECK: [[FBH:%.*]] = tail call {{.*}}<2 x i32> @llvm.[[TARGET]].firstbituhigh.v2i32103// DXCHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 31), [[FBH]]104// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> [[FBH]], splat (i32 -1)105// DXCHECK-NEXT: select <2 x i1> %cmp.i, <2 x i32> splat (i32 -1), <2 x i32> [[SUB]]106// CHECK-NEXT: ret <2 x i32>107uint2 test_firstbithigh_uint2(uint2 p0) {108 return firstbithigh(p0);109}110 111// CHECK-LABEL: test_firstbithigh_uint3112// CHECK: [[FBH:%.*]] = tail call {{.*}}<3 x i32> @llvm.[[TARGET]].firstbituhigh.v3i32113// DXCHECK-NEXT: [[SUB:%.*]] = sub <3 x i32> splat (i32 31), [[FBH]]114// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <3 x i32> [[FBH]], splat (i32 -1)115// DXCHECK-NEXT: select <3 x i1> %cmp.i, <3 x i32> splat (i32 -1), <3 x i32> [[SUB]]116// CHECK-NEXT: ret <3 x i32>117uint3 test_firstbithigh_uint3(uint3 p0) {118 return firstbithigh(p0);119}120 121// CHECK-LABEL: test_firstbithigh_uint4122// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbituhigh.v4i32123// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 31), [[FBH]]124// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)125// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]126// CHECK-NEXT: ret <4 x i32>127uint4 test_firstbithigh_uint4(uint4 p0) {128 return firstbithigh(p0);129}130 131// CHECK-LABEL: test_firstbithigh_ulong132// CHECK: [[FBH:%.*]] = tail call {{.*}}i32 @llvm.[[TARGET]].firstbituhigh.i64133// DXCHECK-NEXT: [[SUB:%.*]] = sub i32 63, [[FBH]]134// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 [[FBH]], -1135// DXCHECK-NEXT: select i1 %cmp.i, i32 -1, i32 [[SUB]]136// CHECK-NEXT: ret i32137uint test_firstbithigh_ulong(uint64_t p0) {138 return firstbithigh(p0);139}140 141// CHECK-LABEL: test_firstbithigh_ulong2142// CHECK: [[FBH:%.*]] = tail call {{.*}}<2 x i32> @llvm.[[TARGET]].firstbituhigh.v2i64143// DXCHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 63), [[FBH]]144// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> [[FBH]], splat (i32 -1)145// DXCHECK-NEXT: select <2 x i1> %cmp.i, <2 x i32> splat (i32 -1), <2 x i32> [[SUB]]146// CHECK-NEXT: ret <2 x i32>147uint2 test_firstbithigh_ulong2(uint64_t2 p0) {148 return firstbithigh(p0);149}150 151// CHECK-LABEL: test_firstbithigh_ulong3152// CHECK: [[FBH:%.*]] = tail call {{.*}}<3 x i32> @llvm.[[TARGET]].firstbituhigh.v3i64153// DXCHECK-NEXT: [[SUB:%.*]] = sub <3 x i32> splat (i32 63), [[FBH]]154// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <3 x i32> [[FBH]], splat (i32 -1)155// DXCHECK-NEXT: select <3 x i1> %cmp.i, <3 x i32> splat (i32 -1), <3 x i32> [[SUB]]156// CHECK-NEXT: ret <3 x i32>157uint3 test_firstbithigh_ulong3(uint64_t3 p0) {158 return firstbithigh(p0);159}160 161// CHECK-LABEL: test_firstbithigh_ulong4162// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbituhigh.v4i64163// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 63), [[FBH]]164// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)165// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]166// CHECK-NEXT: ret <4 x i32>167uint4 test_firstbithigh_ulong4(uint64_t4 p0) {168 return firstbithigh(p0);169}170 171// CHECK-LABEL: test_firstbithigh_int172// CHECK: [[FBH:%.*]] = tail call {{.*}}i32 @llvm.[[TARGET]].firstbitshigh.i32173// DXCHECK-NEXT: [[SUB:%.*]] = sub i32 31, [[FBH]]174// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 [[FBH]], -1175// DXCHECK-NEXT: select i1 %cmp.i, i32 -1, i32 [[SUB]]176// CHECK-NEXT: ret i32177uint test_firstbithigh_int(int p0) {178 return firstbithigh(p0);179}180 181// CHECK-LABEL: test_firstbithigh_int2182// CHECK: [[FBH:%.*]] = tail call {{.*}}<2 x i32> @llvm.[[TARGET]].firstbitshigh.v2i32183// DXCHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 31), [[FBH]]184// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> [[FBH]], splat (i32 -1)185// DXCHECK-NEXT: select <2 x i1> %cmp.i, <2 x i32> splat (i32 -1), <2 x i32> [[SUB]]186// CHECK-NEXT: ret <2 x i32>187uint2 test_firstbithigh_int2(int2 p0) {188 return firstbithigh(p0);189}190 191// CHECK-LABEL: test_firstbithigh_int3192// CHECK: [[FBH:%.*]] = tail call {{.*}}<3 x i32> @llvm.[[TARGET]].firstbitshigh.v3i32193// DXCHECK-NEXT: [[SUB:%.*]] = sub <3 x i32> splat (i32 31), [[FBH]]194// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <3 x i32> [[FBH]], splat (i32 -1)195// DXCHECK-NEXT: select <3 x i1> %cmp.i, <3 x i32> splat (i32 -1), <3 x i32> [[SUB]]196// CHECK-NEXT: ret <3 x i32>197uint3 test_firstbithigh_int3(int3 p0) {198 return firstbithigh(p0);199}200 201// CHECK-LABEL: test_firstbithigh_int4202// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbitshigh.v4i32203// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 31), [[FBH]]204// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)205// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]206// CHECK-NEXT: ret <4 x i32>207uint4 test_firstbithigh_int4(int4 p0) {208 return firstbithigh(p0);209}210 211// CHECK-LABEL: test_firstbithigh_long212// CHECK: [[FBH:%.*]] = tail call {{.*}}i32 @llvm.[[TARGET]].firstbitshigh.i64213// DXCHECK-NEXT: [[SUB:%.*]] = sub i32 63, [[FBH]]214// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq i32 [[FBH]], -1215// DXCHECK-NEXT: select i1 %cmp.i, i32 -1, i32 [[SUB]]216// CHECK-NEXT: ret i32217uint test_firstbithigh_long(int64_t p0) {218 return firstbithigh(p0);219}220 221// CHECK-LABEL: test_firstbithigh_long2222// CHECK: [[FBH:%.*]] = tail call {{.*}}<2 x i32> @llvm.[[TARGET]].firstbitshigh.v2i64223// DXCHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> splat (i32 63), [[FBH]]224// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <2 x i32> [[FBH]], splat (i32 -1)225// DXCHECK-NEXT: select <2 x i1> %cmp.i, <2 x i32> splat (i32 -1), <2 x i32> [[SUB]]226// CHECK-NEXT: ret <2 x i32>227uint2 test_firstbithigh_long2(int64_t2 p0) {228 return firstbithigh(p0);229}230 231// CHECK-LABEL: test_firstbithigh_long3232// CHECK: [[FBH:%.*]] = tail call {{.*}}<3 x i32> @llvm.[[TARGET]].firstbitshigh.v3i64233// DXCHECK-NEXT: [[SUB:%.*]] = sub <3 x i32> splat (i32 63), [[FBH]]234// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <3 x i32> [[FBH]], splat (i32 -1)235// DXCHECK-NEXT: select <3 x i1> %cmp.i, <3 x i32> splat (i32 -1), <3 x i32> [[SUB]]236// CHECK-NEXT: ret <3 x i32>237uint3 test_firstbithigh_long3(int64_t3 p0) {238 return firstbithigh(p0);239}240 241// CHECK-LABEL: test_firstbithigh_long4242// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbitshigh.v4i64243// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 63), [[FBH]]244// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)245// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]246// CHECK-NEXT: ret <4 x i32>247uint4 test_firstbithigh_long4(int64_t4 p0) {248 return firstbithigh(p0);249}250 251// CHECK-LABEL: test_firstbithigh_upcast252// CHECK: [[FBH:%.*]] = tail call {{.*}}<4 x i32> @llvm.[[TARGET]].firstbituhigh.v4i32(<4 x i32> %{{.*}})253// DXCHECK-NEXT: [[SUB:%.*]] = sub <4 x i32> splat (i32 31), [[FBH]]254// DXCHECK-NEXT: [[ICMP:%.*]] = icmp eq <4 x i32> [[FBH]], splat (i32 -1)255// DXCHECK-NEXT: select <4 x i1> %cmp.i, <4 x i32> splat (i32 -1), <4 x i32> [[SUB]]256// CHECK-NEXT: [[ZEXT:%.*]] = zext <4 x i32> {{.*}} to <4 x i64>257// CHECK-NEXT: ret <4 x i64> [[ZEXT]]258uint64_t4 test_firstbithigh_upcast(uint4 p0) {259 return firstbithigh(p0);260}261