| // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ |
| // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ |
| // RUN: -o - | FileCheck %s --check-prefixes=CHECK |
| |
| // CHECK-LABEL: test_select_bool_int |
| // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, i32 {{%.*}}, i32 {{%.*}} |
| // CHECK: ret i32 [[SELECT]] |
| int test_select_bool_int(bool cond0, int tVal, int fVal) { |
| return select<int>(cond0, tVal, fVal); |
| } |
| |
| struct S { int a; }; |
| // CHECK-LABEL: test_select_infer_struct |
| // CHECK: [[TRUE_VAL:%.*]] = load %struct.S, ptr {{%.*}}, align 1 |
| // CHECK: [[FALSE_VAL:%.*]] = load %struct.S, ptr {{%.*}}, align 1 |
| // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, %struct.S [[TRUE_VAL]], %struct.S [[FALSE_VAL]] |
| // CHECK: store %struct.S [[SELECT]], ptr {{%.*}}, align 1 |
| // CHECK: ret void |
| struct S test_select_infer_struct(bool cond0, struct S tVal, struct S fVal) { |
| return select(cond0, tVal, fVal); |
| } |
| |
| // CHECK-LABEL: test_select_infer_array |
| // CHECK: [[TRUE_VAL:%.*]] = load [3 x i32], ptr {{%.*}}, align 4 |
| // CHECK: [[FALSE_VAL:%.*]] = load [3 x i32], ptr {{%.*}}, align 4 |
| // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, [3 x i32] [[TRUE_VAL]], [3 x i32] [[FALSE_VAL]] |
| // CHECK: store [3 x i32] [[SELECT]], ptr {{%.*}}, align 4 |
| // CHECK: ret void |
| int test_select_infer_array(bool cond, int tVal[3], int fVal[3])[3] { |
| return select(cond, tVal, fVal); |
| } |
| |
| // CHECK-LABEL: test_select_bool_vector |
| // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, <2 x i32> {{%.*}}, <2 x i32> {{%.*}} |
| // CHECK: ret <2 x i32> [[SELECT]] |
| int2 test_select_bool_vector(bool cond0, int2 tVal, int2 fVal) { |
| return select<int2>(cond0, tVal, fVal); |
| } |
| |
| // CHECK-LABEL: test_select_vector_1 |
| // CHECK: [[SELECT:%.*]] = select <1 x i1> {{%.*}}, <1 x i32> {{%.*}}, <1 x i32> {{%.*}} |
| // CHECK: ret <1 x i32> [[SELECT]] |
| int1 test_select_vector_1(bool1 cond0, int1 tVals, int1 fVals) { |
| return select<int,1>(cond0, tVals, fVals); |
| } |
| |
| // CHECK-LABEL: test_select_vector_2 |
| // CHECK: [[SELECT:%.*]] = select <2 x i1> {{%.*}}, <2 x i32> {{%.*}}, <2 x i32> {{%.*}} |
| // CHECK: ret <2 x i32> [[SELECT]] |
| int2 test_select_vector_2(bool2 cond0, int2 tVals, int2 fVals) { |
| return select<int,2>(cond0, tVals, fVals); |
| } |
| |
| // CHECK-LABEL: test_select_vector_3 |
| // CHECK: [[SELECT:%.*]] = select <3 x i1> {{%.*}}, <3 x i32> {{%.*}}, <3 x i32> {{%.*}} |
| // CHECK: ret <3 x i32> [[SELECT]] |
| int3 test_select_vector_3(bool3 cond0, int3 tVals, int3 fVals) { |
| return select<int,3>(cond0, tVals, fVals); |
| } |
| |
| // CHECK-LABEL: test_select_vector_4 |
| // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> {{%.*}}, <4 x i32> {{%.*}} |
| // CHECK: ret <4 x i32> [[SELECT]] |
| int4 test_select_vector_4(bool4 cond0, int4 tVals, int4 fVals) { |
| return select(cond0, tVals, fVals); |
| } |
| |
| // CHECK-LABEL: test_select_vector_scalar_vector |
| // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0 |
| // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer |
| // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> [[SPLAT1]], <4 x i32> {{%.*}} |
| // CHECK: ret <4 x i32> [[SELECT]] |
| int4 test_select_vector_scalar_vector(bool4 cond0, int tVal, int4 fVals) { |
| return select(cond0, tVal, fVals); |
| } |
| |
| // CHECK-LABEL: test_select_vector_vector_scalar |
| // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0 |
| // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer |
| // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> {{%.*}}, <4 x i32> [[SPLAT1]] |
| // CHECK: ret <4 x i32> [[SELECT]] |
| int4 test_select_vector_vector_scalar(bool4 cond0, int4 tVals, int fVal) { |
| return select(cond0, tVals, fVal); |
| } |
| |
| // CHECK-LABEL: test_select_vector_scalar_scalar |
| // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0 |
| // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer |
| // CHECK: [[SPLAT_SRC2:%.*]] = insertelement <4 x i32> poison, i32 %3, i64 0 |
| // CHECK: [[SPLAT2:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC2]], <4 x i32> poison, <4 x i32> zeroinitializer |
| // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> [[SPLAT1]], <4 x i32> [[SPLAT2]] |
| // CHECK: ret <4 x i32> [[SELECT]] |
| int4 test_select_vector_scalar_scalar(bool4 cond0, int tVal, int fVal) { |
| return select(cond0, tVal, fVal); |
| } |