1# RUN: llc -march=amdgcn -verify-machineinstrs -run-pass si-shrink-instructions -o - %s | FileCheck -check-prefix=GCN %s
2--- |
3
4  define amdgpu_kernel void @fold_fi_vgpr() {
5    %alloca = alloca [4 x i32], addrspace(5)
6    ret void
7  }
8
9  define amdgpu_kernel void @fold_vgpr_fi() {
10    %alloca = alloca [4 x i32], addrspace(5)
11    ret void
12  }
13
14  define amdgpu_kernel void @fold_sgpr_fi() {
15    %alloca = alloca [4 x i32], addrspace(5)
16    ret void
17  }
18
19  define amdgpu_kernel void @fold_fi_sgpr() {
20    %alloca = alloca [4 x i32], addrspace(5)
21    ret void
22  }
23
24  define amdgpu_kernel void @fold_fi_imm() {
25    %alloca = alloca [4 x i32], addrspace(5)
26    ret void
27  }
28
29  define amdgpu_kernel void @fold_imm_fi() {
30    %alloca = alloca [4 x i32], addrspace(5)
31    ret void
32  }
33
34...
35# GCN-LABEL: name: fold_fi_vgpr{{$}}
36# GCN: %1:vgpr_32 = IMPLICIT_DEF
37
38# GCN: %2:vgpr_32 = V_ADD_I32_e32 %stack.0.alloca, %1, implicit-def $vcc, implicit $exec
39name: fold_fi_vgpr
40tracksRegLiveness: true
41registers:
42  - { id: 0, class: vgpr_32 }
43  - { id: 1, class: vgpr_32 }
44  - { id: 2, class: vgpr_32 }
45stack:
46  - { id: 0, name: alloca, type: default, offset: 0, size: 128, alignment: 8,
47      callee-saved-register: '', local-offset: 0, debug-info-variable: '',
48      debug-info-expression: '', debug-info-location: '' }
49body:             |
50  bb.0:
51    %0 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
52    %1 = IMPLICIT_DEF
53    %2, $vcc = V_ADD_I32_e64 %0, %1, implicit $exec
54    S_ENDPGM
55
56...
57# GCN-LABEL: name: fold_vgpr_fi{{$}}
58# GCN: %1:vgpr_32 = IMPLICIT_DEF
59# GCN: %2:vgpr_32 = V_ADD_I32_e32 %stack.0.alloca, %1, implicit-def $vcc, implicit $exec
60name: fold_vgpr_fi
61tracksRegLiveness: true
62registers:
63  - { id: 0, class: vgpr_32 }
64  - { id: 1, class: vgpr_32 }
65  - { id: 2, class: vgpr_32 }
66stack:
67  - { id: 0, name: alloca, type: default, offset: 0, size: 128, alignment: 8,
68      callee-saved-register: '', local-offset: 0, debug-info-variable: '',
69      debug-info-expression: '', debug-info-location: '' }
70body:             |
71  bb.0:
72    %0 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
73    %1 = IMPLICIT_DEF
74    %2, $vcc = V_ADD_I32_e64 %1, %0, implicit $exec
75    S_ENDPGM
76
77...
78# GCN-LABEL: name: fold_sgpr_fi{{$}}
79# GCN: %0:vgpr_32 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
80# GCN: %1:sgpr_32 = IMPLICIT_DEF
81# GCN: %2:vgpr_32 = V_ADD_I32_e32 %1, %0, implicit-def $vcc, implicit $exec
82name: fold_sgpr_fi
83tracksRegLiveness: true
84registers:
85  - { id: 0, class: vgpr_32 }
86  - { id: 1, class: sgpr_32 }
87  - { id: 2, class: vgpr_32 }
88stack:
89  - { id: 0, name: alloca, type: default, offset: 0, size: 128, alignment: 8,
90      callee-saved-register: '', local-offset: 0, debug-info-variable: '',
91      debug-info-expression: '', debug-info-location: '' }
92body:             |
93  bb.0:
94    %0 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
95    %1 = IMPLICIT_DEF
96    %2, $vcc = V_ADD_I32_e64 %1, %0, implicit $exec
97    S_ENDPGM
98
99...
100# GCN-LABEL: name: fold_fi_sgpr{{$}}
101# GCN: %0:vgpr_32 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
102# GCN: %1:sgpr_32 = IMPLICIT_DEF
103# GCN: %2:vgpr_32 = V_ADD_I32_e32 %1, %0, implicit-def $vcc, implicit $exec
104name: fold_fi_sgpr
105tracksRegLiveness: true
106registers:
107  - { id: 0, class: vgpr_32 }
108  - { id: 1, class: sgpr_32 }
109  - { id: 2, class: vgpr_32 }
110stack:
111  - { id: 0, name: alloca, type: default, offset: 0, size: 128, alignment: 8,
112      callee-saved-register: '', local-offset: 0, debug-info-variable: '',
113      debug-info-expression: '', debug-info-location: '' }
114body:             |
115  bb.0:
116    %0 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
117    %1 = IMPLICIT_DEF
118    %2, $vcc = V_ADD_I32_e64 %0, %1, implicit $exec
119    S_ENDPGM
120...
121# TODO: Should probably prefer folding immediate first
122# GCN-LABEL: name: fold_fi_imm{{$}}
123# GCN: %1:vgpr_32 = V_MOV_B32_e32 999, implicit $exec
124# GCN: %2:vgpr_32 = V_ADD_I32_e32 %stack.0.alloca, %1, implicit-def $vcc, implicit $exec
125name: fold_fi_imm
126tracksRegLiveness: true
127registers:
128  - { id: 0, class: vgpr_32 }
129  - { id: 1, class: vgpr_32 }
130  - { id: 2, class: vgpr_32 }
131stack:
132  - { id: 0, name: alloca, type: default, offset: 0, size: 128, alignment: 8,
133      callee-saved-register: '', local-offset: 0, debug-info-variable: '',
134      debug-info-expression: '', debug-info-location: '' }
135body:             |
136  bb.0:
137    %0 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
138    %1 = V_MOV_B32_e32 999, implicit $exec
139    %2, $vcc = V_ADD_I32_e64 %0, %1, implicit $exec
140    S_ENDPGM
141
142...
143# GCN-LABEL: name: fold_imm_fi{{$}}
144# GCN: %0:vgpr_32 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
145# GCN: %2:vgpr_32 = V_ADD_I32_e32 999, %0, implicit-def $vcc, implicit $exec
146name: fold_imm_fi
147tracksRegLiveness: true
148registers:
149  - { id: 0, class: vgpr_32 }
150  - { id: 1, class: vgpr_32 }
151  - { id: 2, class: vgpr_32 }
152stack:
153  - { id: 0, name: alloca, type: default, offset: 0, size: 128, alignment: 8,
154      callee-saved-register: '', local-offset: 0, debug-info-variable: '',
155      debug-info-expression: '', debug-info-location: '' }
156body:             |
157  bb.0:
158    %0 = V_MOV_B32_e32 %stack.0.alloca, implicit $exec
159    %1 = V_MOV_B32_e32 999, implicit $exec
160    %2, $vcc = V_ADD_I32_e64 %1, %0, implicit $exec
161    S_ENDPGM
162