1 ; RUN: llc -O0 -opaque-pointers=0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3 %struct.ST = type { i32, i32, i32 }
5 ; CHECK-SPIRV: OpName %[[#struct:]] "struct.ST"
6 ; CHECK-SPIRV: %[[#int:]] = OpTypeInt 32 0
7 ; CHECK-SPIRV: %[[#intP:]] = OpTypePointer Function %[[#int]]
8 ; CHECK-SPIRV: %[[#struct]] = OpTypeStruct %[[#int]] %[[#int]] %[[#int]]
9 ; CHECK-SPIRV: %[[#structP:]] = OpTypePointer Function %[[#struct]]
10 ; CHECK-SPIRV: %[[#structPP:]] = OpTypePointer Function %[[#structP]]
11 ; CHECK-SPIRV: %[[#zero:]] = OpConstant %[[#int]] 0
12 ; CHECK-SPIRV: %[[#one:]] = OpConstant %[[#int]] 1
13 ; CHECK-SPIRV: %[[#two:]] = OpConstant %[[#int]] 2
15 define dso_local spir_func i32 @cmp_func(i8* %p1, i8* %p2) {
17 %retval = alloca i32, align 4
18 %p1.addr = alloca i8*, align 8
19 %p2.addr = alloca i8*, align 8
20 ; CHECK-SPIRV: %[[#s1:]] = OpVariable %[[#structPP]]
21 ; CHECK-SPIRV: %[[#s2:]] = OpVariable %[[#structPP]]
22 %s1 = alloca %struct.ST*, align 8
23 %s2 = alloca %struct.ST*, align 8
24 store i8* %p1, i8** %p1.addr, align 8
25 store i8* %p2, i8** %p2.addr, align 8
26 %0 = load i8*, i8** %p1.addr, align 8
27 ; CHECK-SPIRV: %[[#t1:]] = OpBitcast %[[#structP]]
28 ; CHECK-SPIRV: OpStore %[[#s1]] %[[#t1]]
29 %1 = bitcast i8* %0 to %struct.ST*
30 store %struct.ST* %1, %struct.ST** %s1, align 8
31 %2 = load i8*, i8** %p2.addr, align 8
32 ; CHECK-SPIRV: %[[#t2:]] = OpBitcast %[[#structP]]
33 ; CHECK-SPIRV: OpStore %[[#s2]] %[[#t2]]
34 %3 = bitcast i8* %2 to %struct.ST*
35 store %struct.ST* %3, %struct.ST** %s2, align 8
36 ; CHECK-SPIRV: %[[#t3:]] = OpLoad %[[#structP]] %[[#s1]]
37 ; CHECK-SPIRV: %[[#a1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t3]] %[[#zero]] %[[#zero]]
38 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#a1]]
39 %4 = load %struct.ST*, %struct.ST** %s1, align 8
40 %a = getelementptr inbounds %struct.ST, %struct.ST* %4, i32 0, i32 0
41 %5 = load i32, i32* %a, align 4
42 ; CHECK-SPIRV: %[[#t4:]] = OpLoad %[[#structP]] %[[#s2]]
43 ; CHECK-SPIRV: %[[#a2:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t4]] %[[#zero]] %[[#zero]]
44 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#a2]]
45 %6 = load %struct.ST*, %struct.ST** %s2, align 8
46 %a1 = getelementptr inbounds %struct.ST, %struct.ST* %6, i32 0, i32 0
47 %7 = load i32, i32* %a1, align 4
48 %cmp = icmp ne i32 %5, %7
49 br i1 %cmp, label %if.then, label %if.end
51 if.then: ; preds = %entry
52 ; CHECK-SPIRV: %[[#t5:]] = OpLoad %[[#structP]] %[[#s1]]
53 ; CHECK-SPIRV: %[[#a_1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t5]] %[[#zero]] %[[#zero]]
54 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#a_1]]
55 %8 = load %struct.ST*, %struct.ST** %s1, align 8
56 %a2 = getelementptr inbounds %struct.ST, %struct.ST* %8, i32 0, i32 0
57 %9 = load i32, i32* %a2, align 4
58 ; CHECK-SPIRV: %[[#t6:]] = OpLoad %[[#structP]] %[[#s2]]
59 ; CHECK-SPIRV: %[[#a_2:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t6]] %[[#zero]] %[[#zero]]
60 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#a_2]]
61 %10 = load %struct.ST*, %struct.ST** %s2, align 8
62 %a3 = getelementptr inbounds %struct.ST, %struct.ST* %10, i32 0, i32 0
63 %11 = load i32, i32* %a3, align 4
64 %sub = sub nsw i32 %9, %11
65 store i32 %sub, i32* %retval, align 4
68 if.end: ; preds = %entry
69 ; CHECK-SPIRV: %[[#t7:]] = OpLoad %[[#structP]] %[[#s1]]
70 ; CHECK-SPIRV: %[[#b1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t7]] %[[#zero]] %[[#one]]
71 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#b1]]
72 %12 = load %struct.ST*, %struct.ST** %s1, align 8
73 %b = getelementptr inbounds %struct.ST, %struct.ST* %12, i32 0, i32 1
74 %13 = load i32, i32* %b, align 4
75 ; CHECK-SPIRV: %[[#t8:]] = OpLoad %[[#structP]] %[[#s2]]
76 ; CHECK-SPIRV: %[[#b2:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t8]] %[[#zero]] %[[#one]]
77 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#b2]]
78 %14 = load %struct.ST*, %struct.ST** %s2, align 8
79 %b4 = getelementptr inbounds %struct.ST, %struct.ST* %14, i32 0, i32 1
80 %15 = load i32, i32* %b4, align 4
81 %cmp5 = icmp ne i32 %13, %15
82 br i1 %cmp5, label %if.then6, label %if.end10
84 if.then6: ; preds = %if.end
85 ; CHECK-SPIRV: %[[#t9:]] = OpLoad %[[#structP]] %[[#s1]]
86 ; CHECK-SPIRV: %[[#b_1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t9]] %[[#zero]] %[[#one]]
87 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#b_1]]
88 %16 = load %struct.ST*, %struct.ST** %s1, align 8
89 %b7 = getelementptr inbounds %struct.ST, %struct.ST* %16, i32 0, i32 1
90 %17 = load i32, i32* %b7, align 4
91 ; CHECK-SPIRV: %[[#t10:]] = OpLoad %[[#structP]] %[[#s2]]
92 ; CHECK-SPIRV: %[[#b_2:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t10]] %[[#zero]] %[[#one]]
93 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#b_2]]
94 %18 = load %struct.ST*, %struct.ST** %s2, align 8
95 %b8 = getelementptr inbounds %struct.ST, %struct.ST* %18, i32 0, i32 1
96 %19 = load i32, i32* %b8, align 4
97 %sub9 = sub nsw i32 %17, %19
98 store i32 %sub9, i32* %retval, align 4
101 if.end10: ; preds = %if.end
102 ; CHECK-SPIRV: %[[#t11:]] = OpLoad %[[#structP]] %[[#s1]]
103 ; CHECK-SPIRV: %[[#c1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t11]] %[[#zero]] %[[#two]]
104 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#c1]]
105 %20 = load %struct.ST*, %struct.ST** %s1, align 8
106 %c = getelementptr inbounds %struct.ST, %struct.ST* %20, i32 0, i32 2
107 %21 = load i32, i32* %c, align 4
108 ; CHECK-SPIRV: %[[#t12:]] = OpLoad %[[#structP]] %[[#s2]]
109 ; CHECK-SPIRV: %[[#c2:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#t12]] %[[#zero]] %[[#two]]
110 ; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#c2]]
111 %22 = load %struct.ST*, %struct.ST** %s2, align 8
112 %c11 = getelementptr inbounds %struct.ST, %struct.ST* %22, i32 0, i32 2
113 %23 = load i32, i32* %c11, align 4
114 %sub12 = sub nsw i32 %21, %23
115 store i32 %sub12, i32* %retval, align 4
118 return: ; preds = %if.end10, %if.then6, %if.then
119 %24 = load i32, i32* %retval, align 4