; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan %s -o - | FileCheck %s ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o - -filetype=obj | spirv-val %} ; CHECK-DAG: [[glsl_450_ext:%.+]] = OpExtInstImport "GLSL.std.450" ; CHECK-DAG: OpMemoryModel Logical GLSL450 ; CHECK-DAG: [[u32_t:%.+]] = OpTypeInt 32 0 ; CHECK-DAG: [[u32x2_t:%.+]] = OpTypeVector [[u32_t]] 2 ; CHECK-DAG: [[u32x3_t:%.+]] = OpTypeVector [[u32_t]] 3 ; CHECK-DAG: [[u32x4_t:%.+]] = OpTypeVector [[u32_t]] 4 ; CHECK-DAG: [[const_0:%.*]] = OpConstant [[u32_t]] 0 ; CHECK-DAG: [[const_0x2:%.*]] = OpConstantComposite [[u32x2_t]] [[const_0]] [[const_0]] ; CHECK-DAG: [[const_1:%.*]] = OpConstant [[u32_t]] 1 ; CHECK-DAG: [[const_2:%.*]] = OpConstant [[u32_t]] 2 ; CHECK-DAG: [[const_32:%.*]] = OpConstant [[u32_t]] 32 ; CHECK-DAG: [[const_32x2:%.*]] = OpConstantComposite [[u32x2_t]] [[const_32]] [[const_32]] ; CHECK-DAG: [[const_neg1:%.*]] = OpConstant [[u32_t]] 4294967295 ; CHECK-DAG: [[const_neg1x2:%.*]] = OpConstantComposite [[u32x2_t]] [[const_neg1]] [[const_neg1]] ; CHECK-DAG: [[u16_t:%.+]] = OpTypeInt 16 0 ; CHECK-DAG: [[u16x2_t:%.+]] = OpTypeVector [[u16_t]] 2 ; CHECK-DAG: [[u16x3_t:%.+]] = OpTypeVector [[u16_t]] 3 ; CHECK-DAG: [[u16x4_t:%.+]] = OpTypeVector [[u16_t]] 4 ; CHECK-DAG: [[u64_t:%.+]] = OpTypeInt 64 0 ; CHECK-DAG: [[u64x2_t:%.+]] = OpTypeVector [[u64_t]] 2 ; CHECK-DAG: [[u64x3_t:%.+]] = OpTypeVector [[u64_t]] 3 ; CHECK-DAG: [[u64x4_t:%.+]] = OpTypeVector [[u64_t]] 4 ; CHECK-DAG: [[bool_t:%.+]] = OpTypeBool ; CHECK-DAG: [[boolx2_t:%.+]] = OpTypeVector [[bool_t]] 2 ; CHECK-LABEL: Begin function firstbitlow_i32 define noundef i32 @firstbitlow_i32(i32 noundef %a) { entry: ; CHECK: [[a:%.+]] = OpFunctionParameter [[u32_t]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32_t]] [[glsl_450_ext]] FindILsb [[a]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call i32 @llvm.spv.firstbitlow.i32(i32 %a) ret i32 %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v2xi32 define noundef <2 x i32> @firstbitlow_v2xi32(<2 x i32> noundef %a) { entry: ; CHECK: [[a:%.+]] = OpFunctionParameter [[u32x2_t]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32x2_t]] [[glsl_450_ext]] FindILsb [[a]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <2 x i32> @llvm.spv.firstbitlow.v2i32(<2 x i32> %a) ret <2 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v3xi32 define noundef <3 x i32> @firstbitlow_v3xi32(<3 x i32> noundef %a) { entry: ; CHECK: [[a:%.+]] = OpFunctionParameter [[u32x3_t]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32x3_t]] [[glsl_450_ext]] FindILsb [[a]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <3 x i32> @llvm.spv.firstbitlow.v3i32(<3 x i32> %a) ret <3 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v4xi32 define noundef <4 x i32> @firstbitlow_v4xi32(<4 x i32> noundef %a) { entry: ; CHECK: [[a:%.+]] = OpFunctionParameter [[u32x4_t]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32x4_t]] [[glsl_450_ext]] FindILsb [[a]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <4 x i32> @llvm.spv.firstbitlow.v4i32(<4 x i32> %a) ret <4 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_i16 define noundef i32 @firstbitlow_i16(i16 noundef %a) { entry: ; CHECK: [[a16:%.+]] = OpFunctionParameter [[u16_t]] ; CHECK: [[a32:%.+]] = OpUConvert [[u32_t]] [[a16]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32_t]] [[glsl_450_ext]] FindILsb [[a32]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call i32 @llvm.spv.firstbitlow.i16(i16 %a) ret i32 %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v2xi16 define noundef <2 x i32> @firstbitlow_v2xi16(<2 x i16> noundef %a) { entry: ; CHECK: [[a16:%.+]] = OpFunctionParameter [[u16x2_t]] ; CHECK: [[a32:%.+]] = OpUConvert [[u32x2_t]] [[a16]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32x2_t]] [[glsl_450_ext]] FindILsb [[a32]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <2 x i32> @llvm.spv.firstbitlow.v2i16(<2 x i16> %a) ret <2 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v3xi16 define noundef <3 x i32> @firstbitlow_v3xi16(<3 x i16> noundef %a) { entry: ; CHECK: [[a16:%.+]] = OpFunctionParameter [[u16x3_t]] ; CHECK: [[a32:%.+]] = OpUConvert [[u32x3_t]] [[a16]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32x3_t]] [[glsl_450_ext]] FindILsb [[a32]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <3 x i32> @llvm.spv.firstbitlow.v3i16(<3 x i16> %a) ret <3 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v4xi16 define noundef <4 x i32> @firstbitlow_v4xi16(<4 x i16> noundef %a) { entry: ; CHECK: [[a16:%.+]] = OpFunctionParameter [[u16x4_t]] ; CHECK: [[a32:%.+]] = OpUConvert [[u32x4_t]] [[a16]] ; CHECK: [[ret:%.+]] = OpExtInst [[u32x4_t]] [[glsl_450_ext]] FindILsb [[a32]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <4 x i32> @llvm.spv.firstbitlow.v4i16(<4 x i16> %a) ret <4 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_i64 define noundef i32 @firstbitlow_i64(i64 noundef %a) { entry: ; CHECK: [[param:%.+]] = OpFunctionParameter [[u64_t]] ; CHECK: [[bitcast:%.+]] = OpBitcast [[u32x2_t]] [[param]] ; CHECK: [[lsb_bits:%.+]] = OpExtInst [[u32x2_t]] [[glsl_450_ext]] FindILsb [[bitcast]] ; CHECK: [[high_bits:%.+]] = OpVectorExtractDynamic [[u32_t]] [[lsb_bits]] [[const_1]] ; CHECK: [[low_bits:%.+]] = OpVectorExtractDynamic [[u32_t]] [[lsb_bits]] [[const_0]] ; CHECK: [[high_not_neg1:%.+]] = OpINotEqual [[bool_t]] [[high_bits]] [[const_neg1]] ; CHECK: [[low_not_neg1:%.+]] = OpINotEqual [[bool_t]] [[low_bits]] [[const_neg1]] ; CHECK: [[sel0:%.+]] = OpSelect [[u32_t]] [[high_not_neg1]] [[high_bits]] [[const_neg1]] ; CHECK: [[sel1:%.+]] = OpSelect [[u32_t]] [[high_not_neg1]] [[const_32]] [[const_0]] ; CHECK: [[ans_bits:%.+]] = OpSelect [[u32_t]] [[low_not_neg1]] [[low_bits]] [[sel0]] ; CHECK: [[ans_offset:%.+]] = OpSelect [[u32_t]] [[low_not_neg1]] [[const_0]] [[sel1]] ; CHECK: [[ret:%.+]] = OpIAdd [[u32_t]] [[ans_bits]] [[ans_offset]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call i32 @llvm.spv.firstbitlow.i64(i64 %a) ret i32 %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v2xi64 define noundef <2 x i32> @firstbitlow_v2xi64(<2 x i64> noundef %a) { entry: ; CHECK: [[param:%.+]] = OpFunctionParameter [[u64x2_t]] ; CHECK: [[bitcast:%.+]] = OpBitcast [[u32x4_t]] [[param]] ; CHECK: [[lsb_bits:%.+]] = OpExtInst [[u32x4_t]] [[glsl_450_ext]] FindILsb [[bitcast]] ; CHECK: [[high_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[lsb_bits]] [[lsb_bits]] 1 3 ; CHECK: [[low_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[lsb_bits]] [[lsb_bits]] 0 2 ; CHECK: [[high_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[high_bits]] [[const_neg1x2]] ; CHECK: [[low_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[low_bits]] [[const_neg1x2]] ; CHECK: [[sel0:%.+]] = OpSelect [[u32x2_t]] [[high_not_neg1]] [[high_bits]] [[const_neg1x2]] ; CHECK: [[sel1:%.+]] = OpSelect [[u32x2_t]] [[high_not_neg1]] [[const_32x2]] [[const_0x2]] ; CHECK: [[ans_bits:%.+]] = OpSelect [[u32x2_t]] [[low_not_neg1]] [[low_bits]] [[sel0]] ; CHECK: [[ans_offset:%.+]] = OpSelect [[u32x2_t]] [[low_not_neg1]] [[const_0x2]] [[sel1]] ; CHECK: [[ret:%.+]] = OpIAdd [[u32x2_t]] [[ans_bits]] [[ans_offset]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <2 x i32> @llvm.spv.firstbitlow.v2i64(<2 x i64> %a) ret <2 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v3xi64 define noundef <3 x i32> @firstbitlow_v3xi64(<3 x i64> noundef %a) { entry: ; CHECK: [[a:%.+]] = OpFunctionParameter [[u64x3_t]] ; CHECK: [[pt1:%.+]] = OpVectorShuffle [[u64x2_t]] [[a]] [[a]] 0 1 ; CHECK: [[pt1_cast:%.+]] = OpBitcast [[u32x4_t]] [[pt1]] ; CHECK: [[pt1_lsb_bits:%.+]] = OpExtInst [[u32x4_t]] [[glsl_450_ext]] FindILsb [[pt1_cast]] ; CHECK: [[pt1_high_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[pt1_lsb_bits]] [[pt1_lsb_bits]] 1 3 ; CHECK: [[pt1_low_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[pt1_lsb_bits]] [[pt1_lsb_bits]] 0 2 ; CHECK: [[pt1_high_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[pt1_high_bits]] [[const_neg1x2]] ; CHECK: [[pt1_low_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[pt1_low_bits]] [[const_neg1x2]] ; CHECK: [[pt1_sel0:%.+]] = OpSelect [[u32x2_t]] [[pt1_high_not_neg1]] [[pt1_high_bits]] [[const_neg1x2]] ; CHECK: [[pt1_sel1:%.+]] = OpSelect [[u32x2_t]] [[pt1_high_not_neg1]] [[const_32x2]] [[const_0x2]] ; CHECK: [[pt1_ans_bits:%.+]] = OpSelect [[u32x2_t]] [[pt1_low_not_neg1]] [[pt1_low_bits]] [[pt1_sel0]] ; CHECK: [[pt1_ans_offset:%.+]] = OpSelect [[u32x2_t]] [[pt1_low_not_neg1]] [[const_0x2]] [[pt1_sel1]] ; CHECK: [[pt1_ret:%.+]] = OpIAdd [[u32x2_t]] [[pt1_ans_bits]] [[pt1_ans_offset]] ; CHECK: [[pt2:%.+]] = OpVectorExtractDynamic [[u64_t]] [[a]] [[const_2]] ; CHECK: [[pt2_cast:%.+]] = OpBitcast [[u32x2_t]] [[pt2]] ; CHECK: [[pt2_lsb_bits:%.+]] = OpExtInst [[u32x2_t]] [[glsl_450_ext]] FindILsb [[pt2_cast]] ; CHECK: [[pt2_high_bits:%.+]] = OpVectorExtractDynamic [[u32_t]] [[pt2_lsb_bits]] [[const_1]] ; CHECK: [[pt2_low_bits:%.+]] = OpVectorExtractDynamic [[u32_t]] [[pt2_lsb_bits]] [[const_0]] ; CHECK: [[pt2_high_not_neg1:%.+]] = OpINotEqual [[bool_t]] [[pt2_high_bits]] [[const_neg1]] ; CHECK: [[pt2_low_not_neg1:%.+]] = OpINotEqual [[bool_t]] [[pt2_low_bits]] [[const_neg1]] ; CHECK: [[pt2_sel0:%.+]] = OpSelect [[u32_t]] [[pt2_high_not_neg1]] [[pt2_high_bits]] [[const_neg1]] ; CHECK: [[pt2_sel1:%.+]] = OpSelect [[u32_t]] [[pt2_high_not_neg1]] [[const_32]] [[const_0]] ; CHECK: [[pt2_ans_bits:%.+]] = OpSelect [[u32_t]] [[pt2_low_not_neg1]] [[pt2_low_bits]] [[pt2_sel0]] ; CHECK: [[pt2_ans_offset:%.+]] = OpSelect [[u32_t]] [[pt2_low_not_neg1]] [[const_0]] [[pt2_sel1]] ; CHECK: [[pt2_ret:%.+]] = OpIAdd [[u32_t]] [[pt2_ans_bits]] [[pt2_ans_offset]] ; CHECK: [[ret:%.+]] = OpCompositeConstruct [[u32x3_t]] [[pt1_ret]] [[pt2_ret]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <3 x i32> @llvm.spv.firstbitlow.v3i64(<3 x i64> %a) ret <3 x i32> %elt.firstbitlow } ; CHECK-LABEL: Begin function firstbitlow_v4xi64 define noundef <4 x i32> @firstbitlow_v4xi64(<4 x i64> noundef %a) { entry: ; CHECK: [[a:%.+]] = OpFunctionParameter [[u64x4_t]] ; CHECK: [[pt1:%.+]] = OpVectorShuffle [[u64x2_t]] [[a]] [[a]] 0 1 ; CHECK: [[pt1_cast:%.+]] = OpBitcast [[u32x4_t]] [[pt1]] ; CHECK: [[pt1_lsb_bits:%.+]] = OpExtInst [[u32x4_t]] [[glsl_450_ext]] FindILsb [[pt1_cast]] ; CHECK: [[pt1_high_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[pt1_lsb_bits]] [[pt1_lsb_bits]] 1 3 ; CHECK: [[pt1_low_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[pt1_lsb_bits]] [[pt1_lsb_bits]] 0 2 ; CHECK: [[pt1_high_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[pt1_high_bits]] [[const_neg1x2]] ; CHECK: [[pt1_low_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[pt1_low_bits]] [[const_neg1x2]] ; CHECK: [[pt1_sel0:%.+]] = OpSelect [[u32x2_t]] [[pt1_high_not_neg1]] [[pt1_high_bits]] [[const_neg1x2]] ; CHECK: [[pt1_sel1:%.+]] = OpSelect [[u32x2_t]] [[pt1_high_not_neg1]] [[const_32x2]] [[const_0x2]] ; CHECK: [[pt1_ans_bits:%.+]] = OpSelect [[u32x2_t]] [[pt1_low_not_neg1]] [[pt1_low_bits]] [[pt1_sel0]] ; CHECK: [[pt1_ans_offset:%.+]] = OpSelect [[u32x2_t]] [[pt1_low_not_neg1]] [[const_0x2]] [[pt1_sel1]] ; CHECK: [[pt1_ret:%.+]] = OpIAdd [[u32x2_t]] [[pt1_ans_bits]] [[pt1_ans_offset]] ; CHECK: [[pt2:%.+]] = OpVectorShuffle [[u64x2_t]] [[a]] [[a]] 2 3 ; CHECK: [[pt2_cast:%.+]] = OpBitcast [[u32x4_t]] [[pt2]] ; CHECK: [[pt2_lsb_bits:%.+]] = OpExtInst [[u32x4_t]] [[glsl_450_ext]] FindILsb [[pt2_cast]] ; CHECK: [[pt2_high_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[pt2_lsb_bits]] [[pt2_lsb_bits]] 1 3 ; CHECK: [[pt2_low_bits:%.+]] = OpVectorShuffle [[u32x2_t]] [[pt2_lsb_bits]] [[pt2_lsb_bits]] 0 2 ; CHECK: [[pt2_high_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[pt2_high_bits]] [[const_neg1x2]] ; CHECK: [[pt2_low_not_neg1:%.+]] = OpINotEqual [[boolx2_t]] [[pt2_low_bits]] [[const_neg1x2]] ; CHECK: [[pt2_sel0:%.+]] = OpSelect [[u32x2_t]] [[pt2_high_not_neg1]] [[pt2_high_bits]] [[const_neg1x2]] ; CHECK: [[pt2_sel1:%.+]] = OpSelect [[u32x2_t]] [[pt2_high_not_neg1]] [[const_32x2]] [[const_0x2]] ; CHECK: [[pt2_ans_bits:%.+]] = OpSelect [[u32x2_t]] [[pt2_low_not_neg1]] [[pt2_low_bits]] [[pt2_sel0]] ; CHECK: [[pt2_ans_offset:%.+]] = OpSelect [[u32x2_t]] [[pt2_low_not_neg1]] [[const_0x2]] [[pt2_sel1]] ; CHECK: [[pt2_ret:%.+]] = OpIAdd [[u32x2_t]] [[pt2_ans_bits]] [[pt2_ans_offset]] ; CHECK: [[ret:%.+]] = OpCompositeConstruct [[u32x4_t]] [[pt1_ret]] [[pt2_ret]] ; CHECK: OpReturnValue [[ret]] %elt.firstbitlow = call <4 x i32> @llvm.spv.firstbitlow.v4i64(<4 x i64> %a) ret <4 x i32> %elt.firstbitlow } ;declare i16 @llvm.spv.firstbitlow.i16(i16) ;declare i32 @llvm.spv.firstbitlow.i32(i32) ;declare i64 @llvm.spv.firstbitlow.i64(i64) ;declare i16 @llvm.spv.firstbitlow.v2i16(<2 x i16>) ;declare i32 @llvm.spv.firstbitlow.v2i32(<2 x i32>) ;declare i64 @llvm.spv.firstbitlow.v2i64(<2 x i64>)