1*b8e1544bSIlia Diachkov; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
2*b8e1544bSIlia Diachkov
3*b8e1544bSIlia Diachkov; CHECK-DAG: OpName [[FUN:%.+]] "fun"
4*b8e1544bSIlia Diachkov; CHECK-DAG: OpName [[FOO:%.+]] "foo"
5*b8e1544bSIlia Diachkov; CHECK-DAG: OpName [[GOO:%.+]] "goo"
6*b8e1544bSIlia Diachkov
7*b8e1544bSIlia Diachkov; CHECK-NOT: DAG-FENCE
8*b8e1544bSIlia Diachkov
9*b8e1544bSIlia Diachkov; CHECK-DAG: [[I16:%.+]] = OpTypeInt 16
10*b8e1544bSIlia Diachkov; CHECK-DAG: [[I32:%.+]] = OpTypeInt 32
11*b8e1544bSIlia Diachkov; CHECK-DAG: [[I64:%.+]] = OpTypeInt 64
12*b8e1544bSIlia Diachkov; CHECK-DAG: [[FN3:%.+]] = OpTypeFunction [[I32]] [[I32]] [[I16]] [[I64]]
13*b8e1544bSIlia Diachkov; CHECK-DAG: [[PAIR:%.+]] = OpTypeStruct [[I32]] [[I16]]
14*b8e1544bSIlia Diachkov; CHECK-DAG: [[FN1:%.+]] = OpTypeFunction [[I32]] [[I32]]
15*b8e1544bSIlia Diachkov; CHECK-DAG: [[FN2:%.+]] = OpTypeFunction [[I32]] [[PAIR]] [[I64]]
16*b8e1544bSIlia Diachkov; According to the Specification, the OpUndef can be defined in Function.
17*b8e1544bSIlia Diachkov; But the Specification also recommends defining it here. So we enforce that.
18*b8e1544bSIlia Diachkov; CHECK-DAG: [[UNDEF:%.+]] = OpUndef [[PAIR]]
19*b8e1544bSIlia Diachkov
20*b8e1544bSIlia Diachkov
21*b8e1544bSIlia Diachkovdeclare i32 @fun(i32 %value)
22*b8e1544bSIlia Diachkov
23*b8e1544bSIlia Diachkov; Check for @fun declaration
24*b8e1544bSIlia Diachkov; CHECK: [[FUN]] = OpFunction [[I32]] None [[FN1]]
25*b8e1544bSIlia Diachkov; CHECK-NEXT: OpFunctionParameter [[I32]]
26*b8e1544bSIlia Diachkov; CHECK-NEXT: OpFunctionEnd
27*b8e1544bSIlia Diachkov
28*b8e1544bSIlia Diachkov
29*b8e1544bSIlia Diachkovdefine i32 @foo({i32, i16} %in, i64 %unused) {
30*b8e1544bSIlia Diachkov  %first = extractvalue {i32, i16} %in, 0
31*b8e1544bSIlia Diachkov  %bar = call i32 @fun(i32 %first)
32*b8e1544bSIlia Diachkov  ret i32 %bar
33*b8e1544bSIlia Diachkov}
34*b8e1544bSIlia Diachkov
35*b8e1544bSIlia Diachkov; CHECK: [[GOO]] = OpFunction [[I32]] None [[FN3]]
36*b8e1544bSIlia Diachkov; CHECK-NEXT: [[A:%.+]] = OpFunctionParameter [[I32]]
37*b8e1544bSIlia Diachkov; CHECK-NEXT: [[B:%.+]] = OpFunctionParameter [[I16]]
38*b8e1544bSIlia Diachkov; CHECK-NEXT: [[C:%.+]] = OpFunctionParameter [[I64]]
39*b8e1544bSIlia Diachkov; CHECK: [[AGG1:%.+]] = OpCompositeInsert [[PAIR]] [[A]] [[UNDEF]] 0
40*b8e1544bSIlia Diachkov; CHECK: [[AGG2:%.+]] = OpCompositeInsert [[PAIR]] [[B]] [[AGG1]] 1
41*b8e1544bSIlia Diachkov; CHECK: [[RET:%.+]] = OpFunctionCall [[I32]] [[FOO]] [[AGG2]] [[C]]
42*b8e1544bSIlia Diachkov; CHECK: OpReturnValue [[RET]]
43*b8e1544bSIlia Diachkov; CHECK: OpFunctionEnd
44*b8e1544bSIlia Diachkov
45*b8e1544bSIlia Diachkov; CHECK: [[FOO]] = OpFunction [[I32]] None [[FN2]]
46*b8e1544bSIlia Diachkov; CHECK-NEXT: [[IN:%.+]] = OpFunctionParameter [[PAIR]]
47*b8e1544bSIlia Diachkov; CHECK-NEXT: OpFunctionParameter [[I64]]
48*b8e1544bSIlia Diachkov; CHECK: [[FIRST:%.+]] = OpCompositeExtract [[I32]] [[IN]] 0
49*b8e1544bSIlia Diachkov; CHECK: [[BAR:%.+]] = OpFunctionCall [[I32]] [[FUN]] [[FIRST]]
50*b8e1544bSIlia Diachkov; CHECK: OpReturnValue [[BAR]]
51*b8e1544bSIlia Diachkov; CHECK: OpFunctionEnd
52*b8e1544bSIlia Diachkov
53*b8e1544bSIlia Diachkovdefine i32 @goo(i32 %a, i16 %b, i64 %c) {
54*b8e1544bSIlia Diachkov  %agg1 = insertvalue {i32, i16} undef, i32 %a, 0
55*b8e1544bSIlia Diachkov  %agg2 = insertvalue {i32, i16} %agg1, i16 %b, 1
56*b8e1544bSIlia Diachkov  %ret = call i32 @foo({i32, i16} %agg2, i64 %c)
57*b8e1544bSIlia Diachkov  ret i32 %ret
58*b8e1544bSIlia Diachkov}
59*b8e1544bSIlia Diachkov
60*b8e1544bSIlia Diachkov; TODO: test tailcall?
61