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

@ -5,89 +5,91 @@ Linked vertex stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 45
// Id's are bound by 46
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 43 44
EntryPoint Vertex 4 "main" 44 45
Source ESSL 300
Name 4 "main"
Name 8 "i"
Name 13 "A"
Name 20 "B"
Name 23 "C"
Name 29 "D"
Name 32 "E"
Name 34 "F"
Name 40 "G"
Name 43 "gl_VertexID"
Name 44 "gl_InstanceID"
Decorate 43(gl_VertexID) BuiltIn VertexId
Decorate 44(gl_InstanceID) BuiltIn InstanceId
Name 14 "A"
Name 21 "B"
Name 24 "C"
Name 30 "D"
Name 33 "E"
Name 35 "F"
Name 41 "G"
Name 44 "gl_VertexID"
Name 45 "gl_InstanceID"
Decorate 44(gl_VertexID) BuiltIn VertexId
Decorate 45(gl_InstanceID) BuiltIn InstanceId
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
7: TypePointer Function 6(int)
9: 6(int) Constant 0
15: 6(int) Constant 2
16: TypeBool
21: 6(int) Constant 1
25: 6(int) Constant 5
30: 6(int) Constant 3
33: 6(int) Constant 42
35: 6(int) Constant 99
38: 6(int) Constant 19
41: 6(int) Constant 12
42: TypePointer Input 6(int)
43(gl_VertexID): 42(ptr) Variable Input
44(gl_InstanceID): 42(ptr) Variable Input
16: 6(int) Constant 2
17: TypeBool
22: 6(int) Constant 1
26: 6(int) Constant 5
31: 6(int) Constant 3
34: 6(int) Constant 42
36: 6(int) Constant 99
39: 6(int) Constant 19
42: 6(int) Constant 12
43: TypePointer Input 6(int)
44(gl_VertexID): 43(ptr) Variable Input
45(gl_InstanceID): 43(ptr) Variable Input
4(main): 2 Function None 3
5: Label
8(i): 7(ptr) Variable Function
13(A): 7(ptr) Variable Function
20(B): 7(ptr) Variable Function
23(C): 7(ptr) Variable Function
29(D): 7(ptr) Variable Function
32(E): 7(ptr) Variable Function
34(F): 7(ptr) Variable Function
40(G): 7(ptr) Variable Function
14(A): 7(ptr) Variable Function
21(B): 7(ptr) Variable Function
24(C): 7(ptr) Variable Function
30(D): 7(ptr) Variable Function
33(E): 7(ptr) Variable Function
35(F): 7(ptr) Variable Function
41(G): 7(ptr) Variable Function
Store 8(i) 9
Branch 10
10: Label
Store 13(A) 9
14: 6(int) Load 8(i)
17: 16(bool) IEqual 14 15
SelectionMerge 19 None
BranchConditional 17 18 19
11: Label
Store 40(G) 41
Return
LoopMerge 12 13 None
Branch 11
11: Label
Store 14(A) 9
15: 6(int) Load 8(i)
18: 17(bool) IEqual 15 16
SelectionMerge 20 None
BranchConditional 18 19 20
12: Label
36: 6(int) Load 8(i)
37: 6(int) IAdd 36 21
Store 8(i) 37
39: 16(bool) SLessThan 37 38
LoopMerge 11 12 None
BranchConditional 39 10 11
18: Label
Store 20(B) 21
Branch 12
22: Label
Store 23(C) 15
Branch 19
19: Label
24: 6(int) Load 8(i)
26: 16(bool) IEqual 24 25
SelectionMerge 28 None
BranchConditional 26 27 28
27: Label
Store 29(D) 30
Branch 11
31: Label
Store 32(E) 33
Branch 28
28: Label
Store 34(F) 35
Branch 12
FunctionEnd
Store 41(G) 42
Return
13: Label
37: 6(int) Load 8(i)
38: 6(int) IAdd 37 22
Store 8(i) 38
40: 17(bool) SLessThan 38 39
BranchConditional 40 10 12
19: Label
Store 21(B) 22
Branch 13
23: Label
Store 24(C) 16
Branch 20
20: Label
25: 6(int) Load 8(i)
27: 17(bool) IEqual 25 26
SelectionMerge 29 None
BranchConditional 27 28 29
28: Label
Store 30(D) 31
Branch 12
32: Label
Store 33(E) 34
Branch 29
29: Label
Store 35(F) 36
Branch 13
FunctionEnd