Skip to content

Commit 6ce07f1

Browse files
add a shorter test case of a return type mismatch
1 parent cf257d4 commit 6ce07f1

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
; The only pass criterion is that spirv-val considers output valid.
2+
3+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4+
5+
%subgr = type { i64, i64 }
6+
%t_range = type { %t_arr }
7+
%t_arr = type { [1 x i64] }
8+
%t_arr2 = type { [4 x i32] }
9+
10+
define internal spir_func noundef i32 @geti32() {
11+
entry:
12+
ret i32 100
13+
}
14+
15+
define internal spir_func noundef i64 @geti64() {
16+
entry:
17+
ret i64 200
18+
}
19+
20+
define internal spir_func void @enable_if(ptr addrspace(4) noundef align 8 dereferenceable_or_null(8) %this, i64 noundef %dim0) {
21+
entry:
22+
%this.addr = alloca ptr addrspace(4), align 8
23+
%dim0.addr = alloca i64, align 8
24+
store ptr addrspace(4) %this, ptr %this.addr, align 8
25+
store i64 %dim0, ptr %dim0.addr, align 8
26+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
27+
%0 = load i64, ptr %dim0.addr, align 8
28+
call spir_func void @enable_if_2(ptr addrspace(4) noundef align 8 dereferenceable_or_null(8) %this1, i64 noundef %0)
29+
ret void
30+
}
31+
32+
33+
define internal spir_func void @test(ptr addrspace(4) noundef align 8 dereferenceable_or_null(16) %this, ptr addrspace(4) noundef align 4 dereferenceable(16) %bits, ptr noundef byval(%t_range) align 8 %pos) {
34+
entry:
35+
%this.addr = alloca ptr addrspace(4), align 8
36+
%bits.addr = alloca ptr addrspace(4), align 8
37+
%cur_pos = alloca i64, align 8
38+
%__range4 = alloca ptr addrspace(4), align 8
39+
%__begin0 = alloca ptr addrspace(4), align 8
40+
%__end0 = alloca ptr addrspace(4), align 8
41+
%cleanup.dest.slot = alloca i32, align 4
42+
%elem = alloca ptr addrspace(4), align 8
43+
%agg.tmp = alloca %t_range, align 8
44+
%agg.tmp.ascast = addrspacecast ptr %agg.tmp to ptr addrspace(4)
45+
store ptr addrspace(4) %this, ptr %this.addr, align 8
46+
store ptr addrspace(4) %bits, ptr %bits.addr, align 8
47+
%pos.ascast = addrspacecast ptr %pos to ptr addrspace(4)
48+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
49+
%call = call spir_func noundef i64 @getp(ptr addrspace(4) noundef align 8 dereferenceable_or_null(8) %pos.ascast, i32 noundef 0)
50+
store i64 %call, ptr %cur_pos, align 8
51+
%0 = load ptr addrspace(4), ptr %bits.addr, align 8
52+
store ptr addrspace(4) %0, ptr %__range4, align 8
53+
%1 = load ptr addrspace(4), ptr %__range4, align 8
54+
%call2 = call spir_func noundef ptr addrspace(4) @beginp(ptr addrspace(4) noundef align 4 dereferenceable_or_null(16) %1)
55+
store ptr addrspace(4) %call2, ptr %__begin0, align 8
56+
%2 = load ptr addrspace(4), ptr %__range4, align 8
57+
%call3 = call spir_func noundef ptr addrspace(4) @endp(ptr addrspace(4) noundef align 4 dereferenceable_or_null(16) %2)
58+
store ptr addrspace(4) %call3, ptr %__end0, align 8
59+
br label %for.cond
60+
61+
for.cond: ; preds = %for.inc, %entry
62+
%3 = load ptr addrspace(4), ptr %__begin0, align 8
63+
%4 = load ptr addrspace(4), ptr %__end0, align 8
64+
%cmp = icmp ne ptr addrspace(4) %3, %4
65+
br i1 %cmp, label %for.body, label %for.cond.cleanup
66+
67+
for.cond.cleanup: ; preds = %for.cond
68+
br label %for.end
69+
70+
for.body: ; preds = %for.cond
71+
%5 = load ptr addrspace(4), ptr %__begin0, align 8
72+
store ptr addrspace(4) %5, ptr %elem, align 8
73+
%6 = load i64, ptr %cur_pos, align 8
74+
%call4 = call spir_func noundef i32 @maskp(ptr addrspace(4) noundef align 8 dereferenceable_or_null(16) %this1)
75+
%conv = zext i32 %call4 to i64
76+
%cmp5 = icmp ult i64 %6, %conv
77+
br i1 %cmp5, label %if.then, label %if.else
78+
79+
if.then: ; preds = %for.body
80+
%7 = load ptr addrspace(4), ptr %elem, align 8
81+
%8 = load i64, ptr %cur_pos, align 8
82+
call spir_func void @enable_if(ptr addrspace(4) noundef align 8 dereferenceable_or_null(8) %agg.tmp.ascast, i64 noundef %8)
83+
call spir_func void @extract_bits(ptr addrspace(4) noundef align 8 dereferenceable_or_null(16) %this1, ptr addrspace(4) noundef align 4 dereferenceable(4) %7, ptr noundef byval(%t_range) align 8 %agg.tmp)
84+
%9 = load i64, ptr %cur_pos, align 8
85+
%add = add i64 %9, 32
86+
store i64 %add, ptr %cur_pos, align 8
87+
br label %if.end
88+
89+
if.else: ; preds = %for.body
90+
%10 = load ptr addrspace(4), ptr %elem, align 8
91+
store i32 0, ptr addrspace(4) %10, align 4
92+
br label %if.end
93+
94+
if.end: ; preds = %if.else, %if.then
95+
br label %for.inc
96+
97+
for.inc: ; preds = %if.end
98+
%11 = load ptr addrspace(4), ptr %__begin0, align 8
99+
%incdec.ptr = getelementptr inbounds nuw i32, ptr addrspace(4) %11, i32 1
100+
store ptr addrspace(4) %incdec.ptr, ptr %__begin0, align 8
101+
br label %for.cond
102+
103+
for.end: ; preds = %for.cond.cleanup
104+
ret void
105+
}
106+
107+
define internal spir_func noundef i64 @getp(ptr addrspace(4) noundef align 8 dereferenceable_or_null(8) %this, i32 noundef %dimension) {
108+
entry:
109+
%this.addr.i = alloca ptr addrspace(4), align 8
110+
%dimension.addr.i = alloca i32, align 4
111+
%retval = alloca i64, align 8
112+
%this.addr = alloca ptr addrspace(4), align 8
113+
%dimension.addr = alloca i32, align 4
114+
%retval.ascast = addrspacecast ptr %retval to ptr addrspace(4)
115+
store ptr addrspace(4) %this, ptr %this.addr, align 8
116+
store i32 %dimension, ptr %dimension.addr, align 4
117+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
118+
%0 = load i32, ptr %dimension.addr, align 4
119+
store ptr addrspace(4) %this1, ptr %this.addr.i, align 8
120+
store i32 %0, ptr %dimension.addr.i, align 4
121+
%this1.i = load ptr addrspace(4), ptr %this.addr.i, align 8
122+
%common_array1 = bitcast ptr addrspace(4) %this1 to ptr addrspace(4)
123+
%1 = load i32, ptr %dimension.addr, align 4
124+
%idxprom = sext i32 %1 to i64
125+
%arrayidx = getelementptr inbounds [1 x i64], ptr addrspace(4) %common_array1, i64 0, i64 %idxprom
126+
%2 = load i64, ptr addrspace(4) %arrayidx, align 8
127+
ret i64 %2
128+
}
129+
130+
define internal spir_func noundef ptr addrspace(4) @beginp(ptr addrspace(4) noundef align 4 dereferenceable_or_null(16) %this) {
131+
entry:
132+
%retval = alloca ptr addrspace(4), align 8
133+
%this.addr = alloca ptr addrspace(4), align 8
134+
%retval.ascast = addrspacecast ptr %retval to ptr addrspace(4)
135+
store ptr addrspace(4) %this, ptr %this.addr, align 8
136+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
137+
%MData1 = bitcast ptr addrspace(4) %this1 to ptr addrspace(4)
138+
%arraydecay2 = bitcast ptr addrspace(4) %MData1 to ptr addrspace(4)
139+
ret ptr addrspace(4) %arraydecay2
140+
}
141+
142+
define internal spir_func noundef ptr addrspace(4) @endp(ptr addrspace(4) noundef align 4 dereferenceable_or_null(16) %this) {
143+
entry:
144+
%retval = alloca ptr addrspace(4), align 8
145+
%this.addr = alloca ptr addrspace(4), align 8
146+
%retval.ascast = addrspacecast ptr %retval to ptr addrspace(4)
147+
store ptr addrspace(4) %this, ptr %this.addr, align 8
148+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
149+
%MData1 = bitcast ptr addrspace(4) %this1 to ptr addrspace(4)
150+
%arraydecay2 = bitcast ptr addrspace(4) %MData1 to ptr addrspace(4)
151+
%add.ptr = getelementptr inbounds nuw i32, ptr addrspace(4) %arraydecay2, i64 4
152+
ret ptr addrspace(4) %add.ptr
153+
}
154+
155+
define internal spir_func noundef i32 @maskp(ptr addrspace(4) noundef align 8 dereferenceable_or_null(16) %this) {
156+
entry:
157+
%retval = alloca i32, align 4
158+
%this.addr = alloca ptr addrspace(4), align 8
159+
%retval.ascast = addrspacecast ptr %retval to ptr addrspace(4)
160+
store ptr addrspace(4) %this, ptr %this.addr, align 8
161+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
162+
%bits_num = getelementptr inbounds nuw %subgr, ptr addrspace(4) %this1, i32 0, i32 1
163+
%0 = load i64, ptr addrspace(4) %bits_num, align 8
164+
%conv = trunc i64 %0 to i32
165+
ret i32 %conv
166+
}
167+
168+
define internal spir_func void @enable_if_2(ptr addrspace(4) noundef align 8 dereferenceable_or_null(8) %this, i64 noundef %dim0) {
169+
entry:
170+
%this.addr = alloca ptr addrspace(4), align 8
171+
%dim0.addr = alloca i64, align 8
172+
store ptr addrspace(4) %this, ptr %this.addr, align 8
173+
store i64 %dim0, ptr %dim0.addr, align 8
174+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
175+
%common_array1 = bitcast ptr addrspace(4) %this1 to ptr addrspace(4)
176+
%0 = load i64, ptr %dim0.addr, align 8
177+
store i64 %0, ptr addrspace(4) %common_array1, align 8
178+
ret void
179+
}
180+
181+
define internal spir_func void @extract_bits(ptr addrspace(4) noundef align 8 dereferenceable_or_null(16) %this, ptr addrspace(4) noundef align 4 dereferenceable(4) %bits, ptr noundef byval(%t_range) align 8 %pos) {
182+
entry:
183+
%this.addr = alloca ptr addrspace(4), align 8
184+
%bits.addr = alloca ptr addrspace(4), align 8
185+
%Res = alloca i64, align 8
186+
store ptr addrspace(4) %this, ptr %this.addr, align 8
187+
store ptr addrspace(4) %bits, ptr %bits.addr, align 8
188+
%pos.ascast = addrspacecast ptr %pos to ptr addrspace(4)
189+
%this1 = load ptr addrspace(4), ptr %this.addr, align 8
190+
%Bits1 = bitcast ptr addrspace(4) %this1 to ptr addrspace(4)
191+
%0 = load i64, ptr addrspace(4) %Bits1, align 8
192+
store i64 %0, ptr %Res, align 8
193+
%bits_num = getelementptr inbounds nuw %subgr, ptr addrspace(4) %this1, i32 0, i32 1
194+
%1 = load i64, ptr addrspace(4) %bits_num, align 8
195+
%call = call spir_func noundef i64 @geti64()
196+
%2 = load i64, ptr %Res, align 8
197+
%and = and i64 %2, %call
198+
store i64 %and, ptr %Res, align 8
199+
%call2 = call spir_func noundef i64 @geti64()
200+
%call3 = call spir_func noundef i32 @geti32()
201+
%conv = zext i32 %call3 to i64
202+
%cmp = icmp ult i64 %call2, %conv
203+
br i1 %cmp, label %if.then, label %if.else
204+
205+
if.else: ; preds = %entry
206+
%3 = load ptr addrspace(4), ptr %bits.addr, align 8
207+
store i32 0, ptr addrspace(4) %3, align 4
208+
br label %if.end11
209+
210+
if.then: ; preds = %entry
211+
%call4 = call spir_func noundef i64 @geti64()
212+
%cmp5 = icmp ugt i64 %call4, 0
213+
br i1 %cmp5, label %if.then6, label %if.end
214+
215+
if.then6: ; preds = %if.then
216+
%call7 = call spir_func noundef i64 @geti64()
217+
%4 = load i64, ptr %Res, align 8
218+
%shr = lshr i64 %4, %call7
219+
store i64 %shr, ptr %Res, align 8
220+
br label %if.end
221+
222+
if.end: ; preds = %if.then6, %if.then
223+
%call8 = call spir_func noundef i64 @geti64()
224+
%5 = load i64, ptr %Res, align 8
225+
%and9 = and i64 %5, %call8
226+
store i64 %and9, ptr %Res, align 8
227+
%6 = load i64, ptr %Res, align 8
228+
%conv10 = trunc i64 %6 to i32
229+
%7 = load ptr addrspace(4), ptr %bits.addr, align 8
230+
store i32 %conv10, ptr addrspace(4) %7, align 4
231+
br label %if.end11
232+
233+
if.end11: ; preds = %if.else, %if.end
234+
ret void
235+
}

0 commit comments

Comments
 (0)