[PBQP] Conservativelly allocatable nodes can be spilled and give a better solution
[oota-llvm.git] / test / CodeGen / R600 / cttz-ctlz.ll
1 ; RUN: opt -S -codegenprepare -mtriple=r600-unknown-unknown -mcpu=SI < %s | FileCheck -check-prefix=SI -check-prefix=ALL %s
2 ; RUN: opt -S -codegenprepare -mtriple=r600-unknown-unknown -mcpu=tonga < %s | FileCheck -check-prefix=SI -check-prefix=ALL %s
3
4
5 define i64 @test1(i64 %A) {
6 ; ALL-LABEL: @test1(
7 ; SI: [[CTLZ:%[A-Za-z0-9]+]] = call i64 @llvm.ctlz.i64(i64 %A, i1 false)
8 ; SI-NEXT: ret i64 [[CTLZ]]
9 entry:
10   %tobool = icmp eq i64 %A, 0
11   br i1 %tobool, label %cond.end, label %cond.true
12
13 cond.true:                                        ; preds = %entry
14   %0 = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
15   br label %cond.end
16
17 cond.end:                                         ; preds = %entry, %cond.true
18   %cond = phi i64 [ %0, %cond.true ], [ 64, %entry ]
19   ret i64 %cond
20 }
21
22
23 define i32 @test2(i32 %A) {
24 ; ALL-LABEL: @test2(
25 ; SI: [[CTLZ:%[A-Za-z0-9]+]] = call i32 @llvm.ctlz.i32(i32 %A, i1 false)
26 ; SI-NEXT: ret i32 [[CTLZ]]
27 entry:
28   %tobool = icmp eq i32 %A, 0
29   br i1 %tobool, label %cond.end, label %cond.true
30
31 cond.true:                                        ; preds = %entry
32   %0 = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
33   br label %cond.end
34
35 cond.end:                                         ; preds = %entry, %cond.true
36   %cond = phi i32 [ %0, %cond.true ], [ 32, %entry ]
37   ret i32 %cond
38 }
39
40
41 define signext i16 @test3(i16 signext %A) {
42 ; ALL-LABEL: @test3(
43 ; SI: [[CTLZ:%[A-Za-z0-9]+]] = call i16 @llvm.ctlz.i16(i16 %A, i1 false)
44 ; SI-NEXT: ret i16 [[CTLZ]]
45 entry:
46   %tobool = icmp eq i16 %A, 0
47   br i1 %tobool, label %cond.end, label %cond.true
48
49 cond.true:                                        ; preds = %entry
50   %0 = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
51   br label %cond.end
52
53 cond.end:                                         ; preds = %entry, %cond.true
54   %cond = phi i16 [ %0, %cond.true ], [ 16, %entry ]
55   ret i16 %cond
56 }
57
58
59 define i64 @test1b(i64 %A) {
60 ; ALL-LABEL: @test1b(
61 ; SI: [[CTTZ:%[A-Za-z0-9]+]] = call i64 @llvm.cttz.i64(i64 %A, i1 false)
62 ; SI-NEXT: ret i64 [[CTTZ]]
63 entry:
64   %tobool = icmp eq i64 %A, 0
65   br i1 %tobool, label %cond.end, label %cond.true
66
67 cond.true:                                        ; preds = %entry
68   %0 = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
69   br label %cond.end
70
71 cond.end:                                         ; preds = %entry, %cond.true
72   %cond = phi i64 [ %0, %cond.true ], [ 64, %entry ]
73   ret i64 %cond
74 }
75
76
77 define i32 @test2b(i32 %A) {
78 ; ALL-LABEL: @test2b(
79 ; SI: [[CTTZ:%[A-Za-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %A, i1 false)
80 ; SI-NEXT: ret i32 [[CTTZ]]
81 entry:
82   %tobool = icmp eq i32 %A, 0
83   br i1 %tobool, label %cond.end, label %cond.true
84
85 cond.true:                                        ; preds = %entry
86   %0 = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
87   br label %cond.end
88
89 cond.end:                                         ; preds = %entry, %cond.true
90   %cond = phi i32 [ %0, %cond.true ], [ 32, %entry ]
91   ret i32 %cond
92 }
93
94
95 define signext i16 @test3b(i16 signext %A) {
96 ; ALL-LABEL: @test3b(
97 ; SI: [[CTTZ:%[A-Za-z0-9]+]] = call i16 @llvm.cttz.i16(i16 %A, i1 false)
98 ; SI-NEXT: ret i16 [[CTTZ]]
99 entry:
100   %tobool = icmp eq i16 %A, 0
101   br i1 %tobool, label %cond.end, label %cond.true
102
103 cond.true:                                        ; preds = %entry
104   %0 = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
105   br label %cond.end
106
107 cond.end:                                         ; preds = %entry, %cond.true
108   %cond = phi i16 [ %0, %cond.true ], [ 16, %entry ]
109   ret i16 %cond
110 }
111
112
113 define i64 @test1c(i64 %A) {
114 ; ALL-LABEL: @test1c(
115 ; ALL: icmp eq i64 %A, 0
116 ; ALL: call i64 @llvm.ctlz.i64(i64 %A, i1 true)
117 entry:
118   %tobool = icmp eq i64 %A, 0
119   br i1 %tobool, label %cond.end, label %cond.true
120
121 cond.true:                                        ; preds = %entry
122   %0 = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
123   br label %cond.end
124
125 cond.end:                                         ; preds = %entry, %cond.true
126   %cond = phi i64 [ %0, %cond.true ], [ 63, %entry ]
127   ret i64 %cond
128 }
129
130 define i32 @test2c(i32 %A) {
131 ; ALL-LABEL: @test2c(
132 ; ALL: icmp eq i32 %A, 0
133 ; ALL: call i32 @llvm.ctlz.i32(i32 %A, i1 true)
134 entry:
135   %tobool = icmp eq i32 %A, 0
136   br i1 %tobool, label %cond.end, label %cond.true
137
138 cond.true:                                        ; preds = %entry
139   %0 = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
140   br label %cond.end
141
142 cond.end:                                         ; preds = %entry, %cond.true
143   %cond = phi i32 [ %0, %cond.true ], [ 31, %entry ]
144   ret i32 %cond
145 }
146
147
148 define signext i16 @test3c(i16 signext %A) {
149 ; ALL-LABEL: @test3c(
150 ; ALL: icmp eq i16 %A, 0
151 ; ALL: call i16 @llvm.ctlz.i16(i16 %A, i1 true)
152 entry:
153   %tobool = icmp eq i16 %A, 0
154   br i1 %tobool, label %cond.end, label %cond.true
155
156 cond.true:                                        ; preds = %entry
157   %0 = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
158   br label %cond.end
159
160 cond.end:                                         ; preds = %entry, %cond.true
161   %cond = phi i16 [ %0, %cond.true ], [ 15, %entry ]
162   ret i16 %cond
163 }
164
165
166 define i64 @test1d(i64 %A) {
167 ; ALL-LABEL: @test1d(
168 ; ALL: icmp eq i64 %A, 0
169 ; ALL: call i64 @llvm.cttz.i64(i64 %A, i1 true)
170 entry:
171   %tobool = icmp eq i64 %A, 0
172   br i1 %tobool, label %cond.end, label %cond.true
173
174 cond.true:                                        ; preds = %entry
175   %0 = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
176   br label %cond.end
177
178 cond.end:                                         ; preds = %entry, %cond.true
179   %cond = phi i64 [ %0, %cond.true ], [ 63, %entry ]
180   ret i64 %cond
181 }
182
183
184 define i32 @test2d(i32 %A) {
185 ; ALL-LABEL: @test2d(
186 ; ALL: icmp eq i32 %A, 0
187 ; ALL: call i32 @llvm.cttz.i32(i32 %A, i1 true)
188 entry:
189   %tobool = icmp eq i32 %A, 0
190   br i1 %tobool, label %cond.end, label %cond.true
191
192 cond.true:                                        ; preds = %entry
193   %0 = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
194   br label %cond.end
195
196 cond.end:                                         ; preds = %entry, %cond.true
197   %cond = phi i32 [ %0, %cond.true ], [ 31, %entry ]
198   ret i32 %cond
199 }
200
201
202 define signext i16 @test3d(i16 signext %A) {
203 ; ALL-LABEL: @test3d(
204 ; ALL: icmp eq i16 %A, 0
205 ; ALL: call i16 @llvm.cttz.i16(i16 %A, i1 true)
206 entry:
207   %tobool = icmp eq i16 %A, 0
208   br i1 %tobool, label %cond.end, label %cond.true
209
210 cond.true:                                        ; preds = %entry
211   %0 = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
212   br label %cond.end
213
214 cond.end:                                         ; preds = %entry, %cond.true
215   %cond = phi i16 [ %0, %cond.true ], [ 15, %entry ]
216   ret i16 %cond
217 }
218
219
220 declare i64 @llvm.ctlz.i64(i64, i1)
221 declare i32 @llvm.ctlz.i32(i32, i1)
222 declare i16 @llvm.ctlz.i16(i16, i1)
223 declare i64 @llvm.cttz.i64(i64, i1)
224 declare i32 @llvm.cttz.i32(i32, i1)
225 declare i16 @llvm.cttz.i16(i16, i1)