Debian Codegraph @

clang/test/CodeGenHLSL/builtins/select.hlsl

raw
1 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2 // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
3 // RUN: -o - | FileCheck %s --check-prefixes=CHECK
4
5 // CHECK-LABEL: test_select_bool_int
6 // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, i32 {{%.*}}, i32 {{%.*}}
7 // CHECK: ret i32 [[SELECT]]
8 int test_select_bool_int(bool cond0, int tVal, int fVal) {
9 return select<int>(cond0, tVal, fVal);
10 }
11
12 struct S { int a; };
13 // CHECK-LABEL: test_select_infer_struct
14 // CHECK: [[TRUE_VAL:%.*]] = load %struct.S, ptr {{%.*}}, align 1
15 // CHECK: [[FALSE_VAL:%.*]] = load %struct.S, ptr {{%.*}}, align 1
16 // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, %struct.S [[TRUE_VAL]], %struct.S [[FALSE_VAL]]
17 // CHECK: store %struct.S [[SELECT]], ptr {{%.*}}, align 1
18 // CHECK: ret void
19 struct S test_select_infer_struct(bool cond0, struct S tVal, struct S fVal) {
20 return select(cond0, tVal, fVal);
21 }
22
23 // CHECK-LABEL: test_select_bool_vector
24 // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, <2 x i32> {{%.*}}, <2 x i32> {{%.*}}
25 // CHECK: ret <2 x i32> [[SELECT]]
26 int2 test_select_bool_vector(bool cond0, int2 tVal, int2 fVal) {
27 return select<int2>(cond0, tVal, fVal);
28 }
29
30 // CHECK-LABEL: test_select_vector_1
31 // CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, <1 x i32> {{%.*}}, <1 x i32> {{%.*}}
32 // CHECK: ret <1 x i32> [[SELECT]]
33 int1 test_select_vector_1(bool1 cond0, int1 tVals, int1 fVals) {
34 return select(cond0, tVals, fVals);
35 }
36
37 // CHECK-LABEL: test_select_vector_2
38 // CHECK: [[SELECT:%.*]] = select <2 x i1> {{%.*}}, <2 x i32> {{%.*}}, <2 x i32> {{%.*}}
39 // CHECK: ret <2 x i32> [[SELECT]]
40 int2 test_select_vector_2(bool2 cond0, int2 tVals, int2 fVals) {
41 return select(cond0, tVals, fVals);
42 }
43
44 // CHECK-LABEL: test_select_vector_3
45 // CHECK: [[SELECT:%.*]] = select <3 x i1> {{%.*}}, <3 x i32> {{%.*}}, <3 x i32> {{%.*}}
46 // CHECK: ret <3 x i32> [[SELECT]]
47 int3 test_select_vector_3(bool3 cond0, int3 tVals, int3 fVals) {
48 return select(cond0, tVals, fVals);
49 }
50
51 // CHECK-LABEL: test_select_vector_4
52 // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> {{%.*}}, <4 x i32> {{%.*}}
53 // CHECK: ret <4 x i32> [[SELECT]]
54 int4 test_select_vector_4(bool4 cond0, int4 tVals, int4 fVals) {
55 return select(cond0, tVals, fVals);
56 }
57
58 // CHECK-LABEL: test_select_vector_scalar_vector
59 // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0
60 // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer
61 // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> [[SPLAT1]], <4 x i32> {{%.*}}
62 // CHECK: ret <4 x i32> [[SELECT]]
63 int4 test_select_vector_scalar_vector(bool4 cond0, int tVal, int4 fVals) {
64 return select(cond0, tVal, fVals);
65 }
66
67 // CHECK-LABEL: test_select_vector_vector_scalar
68 // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0
69 // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer
70 // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> {{%.*}}, <4 x i32> [[SPLAT1]]
71 // CHECK: ret <4 x i32> [[SELECT]]
72 int4 test_select_vector_vector_scalar(bool4 cond0, int4 tVals, int fVal) {
73 return select(cond0, tVals, fVal);
74 }
75
76 // CHECK-LABEL: test_select_vector_scalar_scalar
77 // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0
78 // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer
79 // CHECK: [[SPLAT_SRC2:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0
80 // CHECK: [[SPLAT2:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC2]], <4 x i32> poison, <4 x i32> zeroinitializer
81 // CHECK: [[SELECT:%.*]] = select <4 x i1> {{%.*}}, <4 x i32> [[SPLAT1]], <4 x i32> [[SPLAT2]]
82 // CHECK: ret <4 x i32> [[SELECT]]
83 int4 test_select_vector_scalar_scalar(bool4 cond0, int tVal, int fVal) {
84 return select(cond0, tVal, fVal);
85 }
86
87 // CHECK-LABEL: test_select_nonbool_cond_vector_4
88 // CHECK: [[TMP0:%.*]] = load <4 x i32>, ptr %cond0.addr, align 16
89 // CHECK: [[TOBOOL:%.*]] = icmp ne <4 x i32> [[TMP0]], zeroinitializer
90 // CHECK: [[SELECT:%.*]] = select <4 x i1> [[TOBOOL]], <4 x i1> {{%.*}}, <4 x i1> {{%.*}}
91 // CHECK: ret <4 x i1> [[SELECT]]
92 bool4 test_select_nonbool_cond_vector_4(int4 cond0, bool4 tVal, bool4 fVal) {
93 return select(cond0, tVal, fVal);
94 }
95
96 // CHECK-LABEL: test_select_nonbool_cond_vector_scalar_vector
97 // CHECK: [[TMP0:%.*]] = load <3 x i32>, ptr %cond0.addr, align 16
98 // CHECK: [[TOBOOL:%.*]] = icmp ne <3 x i32> [[TMP0]], zeroinitializer
99 // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <3 x i32> poison, i32 {{%.*}}, i64 0
100 // CHECK: [[SPLAT1:%.*]] = shufflevector <3 x i32> [[SPLAT_SRC1]], <3 x i32> poison, <3 x i32> zeroinitializer
101 // CHECK: [[SELECT:%.*]] = select <3 x i1> [[TOBOOL]], <3 x i32> [[SPLAT1]], <3 x i32> {{%.*}}
102 // CHECK: ret <3 x i32> [[SELECT]]
103 int3 test_select_nonbool_cond_vector_scalar_vector(int3 cond0, int tVal, int3 fVal) {
104 return select(cond0, tVal, fVal);
105 }
106
107 // CHECK-LABEL: test_select_nonbool_cond_vector_vector_scalar
108 // CHECK: [[TMP0:%.*]] = load <2 x i32>, ptr %cond0.addr, align 8
109 // CHECK: [[TOBOOL:%.*]] = icmp ne <2 x i32> [[TMP0]], zeroinitializer
110 // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <2 x i32> poison, i32 {{%.*}}, i64 0
111 // CHECK: [[SPLAT1:%.*]] = shufflevector <2 x i32> [[SPLAT_SRC1]], <2 x i32> poison, <2 x i32> zeroinitializer
112 // CHECK: [[SELECT:%.*]] = select <2 x i1> [[TOBOOL]], <2 x i32> {{%.*}}, <2 x i32> [[SPLAT1]]
113 // CHECK: ret <2 x i32> [[SELECT]]
114 int2 test_select_nonbool_cond_vector_vector_scalar(int2 cond0, int2 tVal, int fVal) {
115 return select(cond0, tVal, fVal);
116 }
117
118 // CHECK-LABEL: test_select_nonbool_cond_vector_scalar_scalar
119 // CHECK: [[TMP0:%.*]] = load <4 x i32>, ptr %cond0.addr, align 16
120 // CHECK: [[TOBOOL:%.*]] = icmp ne <4 x i32> [[TMP0]], zeroinitializer
121 // CHECK: [[SPLAT_SRC1:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0
122 // CHECK: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC1]], <4 x i32> poison, <4 x i32> zeroinitializer
123 // CHECK: [[SPLAT_SRC2:%.*]] = insertelement <4 x i32> poison, i32 {{%.*}}, i64 0
124 // CHECK: [[SPLAT2:%.*]] = shufflevector <4 x i32> [[SPLAT_SRC2]], <4 x i32> poison, <4 x i32> zeroinitializer
125 // CHECK: [[SELECT:%.*]] = select <4 x i1> [[TOBOOL]], <4 x i32> [[SPLAT1]], <4 x i32> [[SPLAT2]]
126 // CHECK: ret <4 x i32> [[SELECT]]
127 int4 test_select_nonbool_cond_vector_scalar_scalar(int4 cond0, int tVal, int fVal) {
128 return select(cond0, tVal, fVal);
129 }