Fix back-branch target for do-while loops.

To ensure back branches always go to a header block, create a header
block even for !testFirst loops.  Then unify common code between the
testFirst/!testFirst cases.

Generate the header-block code first, so update golden files.

Realize that certain infinite loops generate invalid SPIR-V, so put a
TODO to instead abort code generation in such cases.

Change-Id: I1e173c8f73daad186cfc666b7d72bd563ed7665d
This commit is contained in:
Dejan Mircevski
2016-01-11 15:57:11 -05:00
parent c8fbbab419
commit 832c65c33b
20 changed files with 2062 additions and 2029 deletions

View File

@@ -7,7 +7,7 @@ Linked fragment stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 186
// Id's are bound by 187
Capability Shader
1: ExtInstImport "GLSL.std.450"
@@ -18,53 +18,53 @@ Linked fragment stage:
Name 4 "main"
Name 9 "color"
Name 11 "BaseColor"
Name 17 "bigColor4"
Name 27 "d4"
Name 79 "d13"
Name 139 "gl_FragColor"
Name 141 "bigColor"
Name 142 "bigColor1_1"
Name 143 "bigColor1_2"
Name 144 "bigColor1_3"
Name 145 "bigColor2"
Name 146 "bigColor3"
Name 147 "bigColor5"
Name 148 "bigColor6"
Name 149 "bigColor7"
Name 150 "bigColor8"
Name 151 "d"
Name 152 "d2"
Name 153 "d3"
Name 154 "d5"
Name 155 "d6"
Name 156 "d7"
Name 157 "d8"
Name 158 "d9"
Name 159 "d10"
Name 160 "d11"
Name 161 "d12"
Name 162 "d14"
Name 163 "d15"
Name 164 "d16"
Name 165 "d17"
Name 166 "d18"
Name 167 "d19"
Name 168 "d20"
Name 169 "d21"
Name 170 "d22"
Name 171 "d23"
Name 172 "d24"
Name 173 "d25"
Name 174 "d26"
Name 175 "d27"
Name 176 "d28"
Name 177 "d29"
Name 178 "d30"
Name 179 "d31"
Name 180 "d32"
Name 181 "d33"
Name 182 "d34"
Name 185 "Count"
Name 18 "bigColor4"
Name 28 "d4"
Name 80 "d13"
Name 140 "gl_FragColor"
Name 142 "bigColor"
Name 143 "bigColor1_1"
Name 144 "bigColor1_2"
Name 145 "bigColor1_3"
Name 146 "bigColor2"
Name 147 "bigColor3"
Name 148 "bigColor5"
Name 149 "bigColor6"
Name 150 "bigColor7"
Name 151 "bigColor8"
Name 152 "d"
Name 153 "d2"
Name 154 "d3"
Name 155 "d5"
Name 156 "d6"
Name 157 "d7"
Name 158 "d8"
Name 159 "d9"
Name 160 "d10"
Name 161 "d11"
Name 162 "d12"
Name 163 "d14"
Name 164 "d15"
Name 165 "d16"
Name 166 "d17"
Name 167 "d18"
Name 168 "d19"
Name 169 "d20"
Name 170 "d21"
Name 171 "d22"
Name 172 "d23"
Name 173 "d24"
Name 174 "d25"
Name 175 "d26"
Name 176 "d27"
Name 177 "d28"
Name 178 "d29"
Name 179 "d30"
Name 180 "d31"
Name 181 "d32"
Name 182 "d33"
Name 183 "d34"
Name 186 "Count"
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@@ -72,67 +72,67 @@ Linked fragment stage:
8: TypePointer Function 7(fvec4)
10: TypePointer Input 7(fvec4)
11(BaseColor): 10(ptr) Variable Input
16: TypePointer UniformConstant 7(fvec4)
17(bigColor4): 16(ptr) Variable UniformConstant
21: TypeInt 32 0
22: 21(int) Constant 0
23: TypePointer Function 6(float)
26: TypePointer UniformConstant 6(float)
27(d4): 26(ptr) Variable UniformConstant
29: TypeBool
33: 6(float) Constant 1073741824
34: 21(int) Constant 2
47: 6(float) Constant 1065353216
50: 21(int) Constant 1
76: 21(int) Constant 3
79(d13): 26(ptr) Variable UniformConstant
138: TypePointer Output 7(fvec4)
139(gl_FragColor): 138(ptr) Variable Output
141(bigColor): 16(ptr) Variable UniformConstant
142(bigColor1_1): 16(ptr) Variable UniformConstant
143(bigColor1_2): 16(ptr) Variable UniformConstant
144(bigColor1_3): 16(ptr) Variable UniformConstant
145(bigColor2): 16(ptr) Variable UniformConstant
146(bigColor3): 16(ptr) Variable UniformConstant
147(bigColor5): 16(ptr) Variable UniformConstant
148(bigColor6): 16(ptr) Variable UniformConstant
149(bigColor7): 16(ptr) Variable UniformConstant
150(bigColor8): 16(ptr) Variable UniformConstant
151(d): 26(ptr) Variable UniformConstant
152(d2): 26(ptr) Variable UniformConstant
153(d3): 26(ptr) Variable UniformConstant
154(d5): 26(ptr) Variable UniformConstant
155(d6): 26(ptr) Variable UniformConstant
156(d7): 26(ptr) Variable UniformConstant
157(d8): 26(ptr) Variable UniformConstant
158(d9): 26(ptr) Variable UniformConstant
159(d10): 26(ptr) Variable UniformConstant
160(d11): 26(ptr) Variable UniformConstant
161(d12): 26(ptr) Variable UniformConstant
162(d14): 26(ptr) Variable UniformConstant
163(d15): 26(ptr) Variable UniformConstant
164(d16): 26(ptr) Variable UniformConstant
165(d17): 26(ptr) Variable UniformConstant
166(d18): 26(ptr) Variable UniformConstant
167(d19): 26(ptr) Variable UniformConstant
168(d20): 26(ptr) Variable UniformConstant
169(d21): 26(ptr) Variable UniformConstant
170(d22): 26(ptr) Variable UniformConstant
171(d23): 26(ptr) Variable UniformConstant
172(d24): 26(ptr) Variable UniformConstant
173(d25): 26(ptr) Variable UniformConstant
174(d26): 26(ptr) Variable UniformConstant
175(d27): 26(ptr) Variable UniformConstant
176(d28): 26(ptr) Variable UniformConstant
177(d29): 26(ptr) Variable UniformConstant
178(d30): 26(ptr) Variable UniformConstant
179(d31): 26(ptr) Variable UniformConstant
180(d32): 26(ptr) Variable UniformConstant
181(d33): 26(ptr) Variable UniformConstant
182(d34): 26(ptr) Variable UniformConstant
183: TypeInt 32 1
184: TypePointer UniformConstant 183(int)
185(Count): 184(ptr) Variable UniformConstant
17: TypePointer UniformConstant 7(fvec4)
18(bigColor4): 17(ptr) Variable UniformConstant
22: TypeInt 32 0
23: 22(int) Constant 0
24: TypePointer Function 6(float)
27: TypePointer UniformConstant 6(float)
28(d4): 27(ptr) Variable UniformConstant
30: TypeBool
34: 6(float) Constant 1073741824
35: 22(int) Constant 2
48: 6(float) Constant 1065353216
51: 22(int) Constant 1
77: 22(int) Constant 3
80(d13): 27(ptr) Variable UniformConstant
139: TypePointer Output 7(fvec4)
140(gl_FragColor): 139(ptr) Variable Output
142(bigColor): 17(ptr) Variable UniformConstant
143(bigColor1_1): 17(ptr) Variable UniformConstant
144(bigColor1_2): 17(ptr) Variable UniformConstant
145(bigColor1_3): 17(ptr) Variable UniformConstant
146(bigColor2): 17(ptr) Variable UniformConstant
147(bigColor3): 17(ptr) Variable UniformConstant
148(bigColor5): 17(ptr) Variable UniformConstant
149(bigColor6): 17(ptr) Variable UniformConstant
150(bigColor7): 17(ptr) Variable UniformConstant
151(bigColor8): 17(ptr) Variable UniformConstant
152(d): 27(ptr) Variable UniformConstant
153(d2): 27(ptr) Variable UniformConstant
154(d3): 27(ptr) Variable UniformConstant
155(d5): 27(ptr) Variable UniformConstant
156(d6): 27(ptr) Variable UniformConstant
157(d7): 27(ptr) Variable UniformConstant
158(d8): 27(ptr) Variable UniformConstant
159(d9): 27(ptr) Variable UniformConstant
160(d10): 27(ptr) Variable UniformConstant
161(d11): 27(ptr) Variable UniformConstant
162(d12): 27(ptr) Variable UniformConstant
163(d14): 27(ptr) Variable UniformConstant
164(d15): 27(ptr) Variable UniformConstant
165(d16): 27(ptr) Variable UniformConstant
166(d17): 27(ptr) Variable UniformConstant
167(d18): 27(ptr) Variable UniformConstant
168(d19): 27(ptr) Variable UniformConstant
169(d20): 27(ptr) Variable UniformConstant
170(d21): 27(ptr) Variable UniformConstant
171(d22): 27(ptr) Variable UniformConstant
172(d23): 27(ptr) Variable UniformConstant
173(d24): 27(ptr) Variable UniformConstant
174(d25): 27(ptr) Variable UniformConstant
175(d26): 27(ptr) Variable UniformConstant
176(d27): 27(ptr) Variable UniformConstant
177(d28): 27(ptr) Variable UniformConstant
178(d29): 27(ptr) Variable UniformConstant
179(d30): 27(ptr) Variable UniformConstant
180(d31): 27(ptr) Variable UniformConstant
181(d32): 27(ptr) Variable UniformConstant
182(d33): 27(ptr) Variable UniformConstant
183(d34): 27(ptr) Variable UniformConstant
184: TypeInt 32 1
185: TypePointer UniformConstant 184(int)
186(Count): 185(ptr) Variable UniformConstant
4(main): 2 Function None 3
5: Label
9(color): 8(ptr) Variable Function
@@ -140,160 +140,162 @@ Linked fragment stage:
Store 9(color) 12
Branch 13
13: Label
18: 7(fvec4) Load 17(bigColor4)
19: 7(fvec4) Load 9(color)
20: 7(fvec4) FAdd 19 18
Store 9(color) 20
24: 23(ptr) AccessChain 9(color) 22
25: 6(float) Load 24
28: 6(float) Load 27(d4)
30: 29(bool) FOrdLessThan 25 28
SelectionMerge 32 None
BranchConditional 30 31 32
14: Label
Branch 75
LoopMerge 15 16 None
Branch 14
14: Label
19: 7(fvec4) Load 18(bigColor4)
20: 7(fvec4) Load 9(color)
21: 7(fvec4) FAdd 20 19
Store 9(color) 21
25: 24(ptr) AccessChain 9(color) 23
26: 6(float) Load 25
29: 6(float) Load 28(d4)
31: 30(bool) FOrdLessThan 26 29
SelectionMerge 33 None
BranchConditional 31 32 33
15: Label
68: 23(ptr) AccessChain 9(color) 34
69: 6(float) Load 68
70: 6(float) Load 27(d4)
71: 29(bool) FOrdLessThan 69 70
LoopMerge 14 15 None
BranchConditional 71 13 14
31: Label
35: 23(ptr) AccessChain 9(color) 34
36: 6(float) Load 35
37: 6(float) FAdd 36 33
38: 23(ptr) AccessChain 9(color) 34
Store 38 37
39: 23(ptr) AccessChain 9(color) 34
40: 6(float) Load 39
41: 6(float) Load 27(d4)
42: 29(bool) FOrdLessThan 40 41
SelectionMerge 44 None
BranchConditional 42 43 44
43: Label
45: 23(ptr) AccessChain 9(color) 22
46: 6(float) Load 45
48: 6(float) FAdd 46 47
Store 45 48
Branch 15
Branch 73
16: Label
69: 24(ptr) AccessChain 9(color) 35
70: 6(float) Load 69
71: 6(float) Load 28(d4)
72: 30(bool) FOrdLessThan 70 71
BranchConditional 72 13 15
32: Label
36: 24(ptr) AccessChain 9(color) 35
37: 6(float) Load 36
38: 6(float) FAdd 37 34
39: 24(ptr) AccessChain 9(color) 35
Store 39 38
40: 24(ptr) AccessChain 9(color) 35
41: 6(float) Load 40
42: 6(float) Load 28(d4)
43: 30(bool) FOrdLessThan 41 42
SelectionMerge 45 None
BranchConditional 43 44 45
44: Label
Branch 32
32: Label
51: 23(ptr) AccessChain 9(color) 50
52: 6(float) Load 51
53: 6(float) Load 27(d4)
54: 29(bool) FOrdLessThan 52 53
SelectionMerge 56 None
BranchConditional 54 55 62
55: Label
57: 6(float) Load 27(d4)
58: 23(ptr) AccessChain 9(color) 50
59: 6(float) Load 58
60: 6(float) FAdd 59 57
61: 23(ptr) AccessChain 9(color) 50
Store 61 60
Branch 56
62: Label
63: 6(float) Load 27(d4)
64: 23(ptr) AccessChain 9(color) 22
65: 6(float) Load 64
66: 6(float) FAdd 65 63
67: 23(ptr) AccessChain 9(color) 22
Store 67 66
Branch 56
56: Label
Branch 15
72: Label
82: 23(ptr) AccessChain 9(color) 34
83: 6(float) Load 82
84: 6(float) Load 79(d13)
85: 29(bool) FOrdLessThan 83 84
SelectionMerge 87 None
BranchConditional 85 86 91
73: Label
135: 7(fvec4) Load 9(color)
136: 7(fvec4) CompositeConstruct 47 47 47 47
137: 7(fvec4) FAdd 135 136
Store 9(color) 137
140: 7(fvec4) Load 9(color)
Store 139(gl_FragColor) 140
Return
74: Label
Branch 75
75: Label
77: 23(ptr) AccessChain 9(color) 76
78: 6(float) Load 77
80: 6(float) Load 79(d13)
81: 29(bool) FOrdLessThan 78 80
LoopMerge 73 74 None
BranchConditional 81 72 73
86: Label
88: 7(fvec4) Load 9(color)
89: 7(fvec4) CompositeConstruct 47 47 47 47
90: 7(fvec4) FAdd 88 89
Store 9(color) 90
Branch 87
91: Label
92: 7(fvec4) Load 9(color)
93: 7(fvec4) CompositeConstruct 47 47 47 47
94: 7(fvec4) FSub 92 93
Store 9(color) 94
Branch 87
87: Label
95: 7(fvec4) Load 17(bigColor4)
96: 7(fvec4) Load 9(color)
97: 7(fvec4) FAdd 96 95
Store 9(color) 97
98: 23(ptr) AccessChain 9(color) 22
99: 6(float) Load 98
100: 6(float) Load 27(d4)
101: 29(bool) FOrdLessThan 99 100
SelectionMerge 103 None
BranchConditional 101 102 103
102: Label
104: 23(ptr) AccessChain 9(color) 34
105: 6(float) Load 104
106: 6(float) FAdd 105 33
107: 23(ptr) AccessChain 9(color) 34
Store 107 106
108: 23(ptr) AccessChain 9(color) 34
109: 6(float) Load 108
110: 6(float) Load 27(d4)
111: 29(bool) FOrdLessThan 109 110
SelectionMerge 113 None
BranchConditional 111 112 113
112: Label
114: 23(ptr) AccessChain 9(color) 22
115: 6(float) Load 114
116: 6(float) FAdd 115 47
Store 114 116
Branch 74
113: Label
Branch 103
103: Label
118: 23(ptr) AccessChain 9(color) 50
119: 6(float) Load 118
120: 6(float) Load 27(d4)
121: 29(bool) FOrdLessThan 119 120
SelectionMerge 123 None
BranchConditional 121 122 129
122: Label
124: 6(float) Load 27(d4)
125: 23(ptr) AccessChain 9(color) 50
126: 6(float) Load 125
127: 6(float) FAdd 126 124
128: 23(ptr) AccessChain 9(color) 50
Store 128 127
Branch 123
129: Label
130: 6(float) Load 27(d4)
131: 23(ptr) AccessChain 9(color) 22
132: 6(float) Load 131
133: 6(float) FAdd 132 130
134: 23(ptr) AccessChain 9(color) 22
Store 134 133
Branch 123
123: Label
Branch 74
FunctionEnd
46: 24(ptr) AccessChain 9(color) 23
47: 6(float) Load 46
49: 6(float) FAdd 47 48
Store 46 49
Branch 16
45: Label
Branch 33
33: Label
52: 24(ptr) AccessChain 9(color) 51
53: 6(float) Load 52
54: 6(float) Load 28(d4)
55: 30(bool) FOrdLessThan 53 54
SelectionMerge 57 None
BranchConditional 55 56 63
56: Label
58: 6(float) Load 28(d4)
59: 24(ptr) AccessChain 9(color) 51
60: 6(float) Load 59
61: 6(float) FAdd 60 58
62: 24(ptr) AccessChain 9(color) 51
Store 62 61
Branch 57
63: Label
64: 6(float) Load 28(d4)
65: 24(ptr) AccessChain 9(color) 23
66: 6(float) Load 65
67: 6(float) FAdd 66 64
68: 24(ptr) AccessChain 9(color) 23
Store 68 67
Branch 57
57: Label
Branch 16
73: Label
78: 24(ptr) AccessChain 9(color) 77
79: 6(float) Load 78
81: 6(float) Load 80(d13)
82: 30(bool) FOrdLessThan 79 81
LoopMerge 75 76 None
BranchConditional 82 74 75
74: Label
83: 24(ptr) AccessChain 9(color) 35
84: 6(float) Load 83
85: 6(float) Load 80(d13)
86: 30(bool) FOrdLessThan 84 85
SelectionMerge 88 None
BranchConditional 86 87 92
75: Label
136: 7(fvec4) Load 9(color)
137: 7(fvec4) CompositeConstruct 48 48 48 48
138: 7(fvec4) FAdd 136 137
Store 9(color) 138
141: 7(fvec4) Load 9(color)
Store 140(gl_FragColor) 141
Return
76: Label
Branch 73
87: Label
89: 7(fvec4) Load 9(color)
90: 7(fvec4) CompositeConstruct 48 48 48 48
91: 7(fvec4) FAdd 89 90
Store 9(color) 91
Branch 88
92: Label
93: 7(fvec4) Load 9(color)
94: 7(fvec4) CompositeConstruct 48 48 48 48
95: 7(fvec4) FSub 93 94
Store 9(color) 95
Branch 88
88: Label
96: 7(fvec4) Load 18(bigColor4)
97: 7(fvec4) Load 9(color)
98: 7(fvec4) FAdd 97 96
Store 9(color) 98
99: 24(ptr) AccessChain 9(color) 23
100: 6(float) Load 99
101: 6(float) Load 28(d4)
102: 30(bool) FOrdLessThan 100 101
SelectionMerge 104 None
BranchConditional 102 103 104
103: Label
105: 24(ptr) AccessChain 9(color) 35
106: 6(float) Load 105
107: 6(float) FAdd 106 34
108: 24(ptr) AccessChain 9(color) 35
Store 108 107
109: 24(ptr) AccessChain 9(color) 35
110: 6(float) Load 109
111: 6(float) Load 28(d4)
112: 30(bool) FOrdLessThan 110 111
SelectionMerge 114 None
BranchConditional 112 113 114
113: Label
115: 24(ptr) AccessChain 9(color) 23
116: 6(float) Load 115
117: 6(float) FAdd 116 48
Store 115 117
Branch 76
114: Label
Branch 104
104: Label
119: 24(ptr) AccessChain 9(color) 51
120: 6(float) Load 119
121: 6(float) Load 28(d4)
122: 30(bool) FOrdLessThan 120 121
SelectionMerge 124 None
BranchConditional 122 123 130
123: Label
125: 6(float) Load 28(d4)
126: 24(ptr) AccessChain 9(color) 51
127: 6(float) Load 126
128: 6(float) FAdd 127 125
129: 24(ptr) AccessChain 9(color) 51
Store 129 128
Branch 124
130: Label
131: 6(float) Load 28(d4)
132: 24(ptr) AccessChain 9(color) 23
133: 6(float) Load 132
134: 6(float) FAdd 133 131
135: 24(ptr) AccessChain 9(color) 23
Store 135 134
Branch 124
124: Label
Branch 76
FunctionEnd