1 ; The goal of the test is to check that newly inserted `ptrcast` internal
2 ; intrinsic functions for PHI's operands are inserted at the correct
3 ; positions, and don't break rules of instruction domination and PHI nodes
4 ; grouping at top of basic block.
6 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
7 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
10 ; CHECK-DAG: OpName %[[#Case1:]] "case1"
11 ; CHECK-DAG: OpName %[[#Case2:]] "case2"
12 ; CHECK-DAG: OpName %[[#Case3:]] "case3"
14 %struct1 = type { i64 }
15 %struct2 = type { i64, i64 }
17 @.str.1 = private unnamed_addr addrspace(1) constant [3 x i8] c"OK\00", align 1
18 @.str.2 = private unnamed_addr addrspace(1) constant [6 x i8] c"WRONG\00", align 1
20 ; CHECK: %[[#Case1]] = OpFunction
21 define spir_func void @case1(i1 %b1, i1 %b2, i1 %b3) {
23 ; CHECK: OpBranchConditional %[[#]] %[[#l1:]] %[[#l2:]]
24 br i1 %b1, label %l1, label %l2
27 %str = phi ptr addrspace(1) [ @.str.1, %entry ], [ @.str.2, %l2 ], [ @.str.2, %l3 ]
30 ; CHECK: %[[#l2]] = OpLabel
31 ; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#l3:]]
33 br i1 %b2, label %l1, label %l3
35 ; CHECK: %[[#l3]] = OpLabel
36 ; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#exit:]]
38 br i1 %b3, label %l1, label %exit
40 ; CHECK: %[[#l1]] = OpLabel
42 ; CHECK: OpBranch %[[#exit]]
44 ; CHECK: %[[#exit]] = OpLabel
51 ; CHECK: %[[#Case2]] = OpFunction
52 define spir_func void @case2(i1 %b1, i1 %b2, i1 %b3, ptr addrspace(1) byval(%struct1) %str1, ptr addrspace(1) byval(%struct2) %str2) {
54 ; CHECK: OpBranchConditional %[[#]] %[[#l1:]] %[[#l2:]]
55 br i1 %b1, label %l1, label %l2
58 %str = phi ptr addrspace(1) [ %str1, %entry ], [ %str2, %l2 ], [ %str2, %l3 ]
61 ; CHECK: %[[#l2]] = OpLabel
62 ; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#l3:]]
64 br i1 %b2, label %l1, label %l3
66 ; CHECK: %[[#l3]] = OpLabel
67 ; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#exit:]]
69 br i1 %b3, label %l1, label %exit
71 ; CHECK: %[[#l1]] = OpLabel
73 ; CHECK: OpBranch %[[#exit]]
75 ; CHECK: %[[#exit]] = OpLabel
81 ; CHECK: %[[#Case3]] = OpFunction
82 define spir_func void @case3(i1 %b1, i1 %b2, i1 %b3, ptr addrspace(1) byval(%struct1) %_arg_str1, ptr addrspace(1) byval(%struct2) %_arg_str2) {
84 ; CHECK: OpBranchConditional %[[#]] %[[#l1:]] %[[#l2:]]
86 br i1 %b1, label %l1, label %l2
89 %str = phi ptr addrspace(1) [ %_arg_str1, %entry ], [ %str2, %l2 ], [ %str3, %l3 ]
92 ; CHECK: %[[#l2]] = OpLabel
93 ; CHECK: OpInBoundsPtrAccessChain
94 ; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#l3:]]
96 %str2 = getelementptr inbounds %struct2, ptr addrspace(1) %_arg_str2, i32 1
97 br i1 %b2, label %l1, label %l3
99 ; CHECK: %[[#l3]] = OpLabel
100 ; CHECK: OpInBoundsPtrAccessChain
101 ; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#exit:]]
103 %str3 = getelementptr inbounds %struct2, ptr addrspace(1) %_arg_str2, i32 2
104 br i1 %b3, label %l1, label %exit
106 ; CHECK: %[[#l1]] = OpLabel
108 ; CHECK: OpBranch %[[#exit]]
110 ; CHECK: %[[#exit]] = OpLabel