1 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -mtriple=amdgcn-unknown-unknown -mcpu=tahiti < %s | FileCheck -check-prefix=SI -check-prefix=ALL %s
2 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -mtriple=amdgcn-unknown-unknown -mcpu=tonga < %s | FileCheck -check-prefix=SI -check-prefix=ALL %s
5 define i64 @test1(i64 %A) {
7 ; SI: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i64 %A, 0
8 ; SI-NEXT: [[CTLZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
9 ; SI-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i64 64, i64 [[CTLZ]]
10 ; SI-NEXT: ret i64 [[SEL]]
12 %tobool = icmp eq i64 %A, 0
13 br i1 %tobool, label %cond.end, label %cond.true
15 cond.true: ; preds = %entry
16 %0 = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
19 cond.end: ; preds = %entry, %cond.true
20 %cond = phi i64 [ %0, %cond.true ], [ 64, %entry ]
25 define i32 @test2(i32 %A) {
27 ; SI: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0
28 ; SI-NEXT: [[CTLZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
29 ; SI-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i32 32, i32 [[CTLZ]]
30 ; SI-NEXT: ret i32 [[SEL]]
32 %tobool = icmp eq i32 %A, 0
33 br i1 %tobool, label %cond.end, label %cond.true
35 cond.true: ; preds = %entry
36 %0 = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
39 cond.end: ; preds = %entry, %cond.true
40 %cond = phi i32 [ %0, %cond.true ], [ 32, %entry ]
45 define signext i16 @test3(i16 signext %A) {
47 ; SI: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i16 %A, 0
48 ; SI-NEXT: [[CTLZ:%[A-Za-z0-9]+]] = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
49 ; SI-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i16 16, i16 [[CTLZ]]
50 ; SI-NEXT: ret i16 [[SEL]]
52 %tobool = icmp eq i16 %A, 0
53 br i1 %tobool, label %cond.end, label %cond.true
55 cond.true: ; preds = %entry
56 %0 = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
59 cond.end: ; preds = %entry, %cond.true
60 %cond = phi i16 [ %0, %cond.true ], [ 16, %entry ]
65 define i64 @test1b(i64 %A) {
67 ; SI: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i64 %A, 0
68 ; SI-NEXT: [[CTTZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
69 ; SI-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i64 64, i64 [[CTTZ]]
70 ; SI-NEXT: ret i64 [[SEL]]
72 %tobool = icmp eq i64 %A, 0
73 br i1 %tobool, label %cond.end, label %cond.true
75 cond.true: ; preds = %entry
76 %0 = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
79 cond.end: ; preds = %entry, %cond.true
80 %cond = phi i64 [ %0, %cond.true ], [ 64, %entry ]
85 define i32 @test2b(i32 %A) {
87 ; SI: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0
88 ; SI-NEXT: [[CTTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
89 ; SI-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i32 32, i32 [[CTTZ]]
90 ; SI-NEXT: ret i32 [[SEL]]
92 %tobool = icmp eq i32 %A, 0
93 br i1 %tobool, label %cond.end, label %cond.true
95 cond.true: ; preds = %entry
96 %0 = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
99 cond.end: ; preds = %entry, %cond.true
100 %cond = phi i32 [ %0, %cond.true ], [ 32, %entry ]
105 define signext i16 @test3b(i16 signext %A) {
106 ; ALL-LABEL: @test3b(
107 ; SI: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i16 %A, 0
108 ; SI-NEXT: [[CTTZ:%[A-Za-z0-9]+]] = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
109 ; SI-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i16 16, i16 [[CTTZ]]
110 ; SI-NEXT: ret i16 [[SEL]]
112 %tobool = icmp eq i16 %A, 0
113 br i1 %tobool, label %cond.end, label %cond.true
115 cond.true: ; preds = %entry
116 %0 = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
119 cond.end: ; preds = %entry, %cond.true
120 %cond = phi i16 [ %0, %cond.true ], [ 16, %entry ]
125 define i64 @test1c(i64 %A) {
126 ; ALL-LABEL: @test1c(
127 ; ALL: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i64 %A, 0
128 ; ALL-NEXT: [[CTLZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
129 ; ALL-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i64 63, i64 [[CTLZ]]
130 ; ALL-NEXT: ret i64 [[SEL]]
132 %tobool = icmp eq i64 %A, 0
133 br i1 %tobool, label %cond.end, label %cond.true
135 cond.true: ; preds = %entry
136 %0 = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
139 cond.end: ; preds = %entry, %cond.true
140 %cond = phi i64 [ %0, %cond.true ], [ 63, %entry ]
144 define i32 @test2c(i32 %A) {
145 ; ALL-LABEL: @test2c(
146 ; ALL: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0
147 ; ALL-NEXT: [[CTLZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
148 ; ALL-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i32 31, i32 [[CTLZ]]
149 ; ALL-NEXT: ret i32 [[SEL]]
151 %tobool = icmp eq i32 %A, 0
152 br i1 %tobool, label %cond.end, label %cond.true
154 cond.true: ; preds = %entry
155 %0 = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
158 cond.end: ; preds = %entry, %cond.true
159 %cond = phi i32 [ %0, %cond.true ], [ 31, %entry ]
164 define signext i16 @test3c(i16 signext %A) {
165 ; ALL-LABEL: @test3c(
166 ; ALL: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i16 %A, 0
167 ; ALL-NEXT: [[CTLZ:%[A-Za-z0-9]+]] = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
168 ; ALL-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i16 15, i16 [[CTLZ]]
169 ; ALL-NEXT: ret i16 [[SEL]]
171 %tobool = icmp eq i16 %A, 0
172 br i1 %tobool, label %cond.end, label %cond.true
174 cond.true: ; preds = %entry
175 %0 = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
178 cond.end: ; preds = %entry, %cond.true
179 %cond = phi i16 [ %0, %cond.true ], [ 15, %entry ]
184 define i64 @test1d(i64 %A) {
185 ; ALL-LABEL: @test1d(
186 ; ALL: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i64 %A, 0
187 ; ALL-NEXT: [[CTTZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
188 ; ALL-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i64 63, i64 [[CTTZ]]
189 ; ALL-NEXT: ret i64 [[SEL]]
191 %tobool = icmp eq i64 %A, 0
192 br i1 %tobool, label %cond.end, label %cond.true
194 cond.true: ; preds = %entry
195 %0 = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
198 cond.end: ; preds = %entry, %cond.true
199 %cond = phi i64 [ %0, %cond.true ], [ 63, %entry ]
204 define i32 @test2d(i32 %A) {
205 ; ALL-LABEL: @test2d(
206 ; ALL: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0
207 ; ALL-NEXT: [[CTTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
208 ; ALL-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i32 31, i32 [[CTTZ]]
209 ; ALL-NEXT: ret i32 [[SEL]]
211 %tobool = icmp eq i32 %A, 0
212 br i1 %tobool, label %cond.end, label %cond.true
214 cond.true: ; preds = %entry
215 %0 = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
218 cond.end: ; preds = %entry, %cond.true
219 %cond = phi i32 [ %0, %cond.true ], [ 31, %entry ]
224 define signext i16 @test3d(i16 signext %A) {
225 ; ALL-LABEL: @test3d(
226 ; ALL: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i16 %A, 0
227 ; ALL-NEXT: [[CTTZ:%[A-Za-z0-9]+]] = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
228 ; ALL-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i16 15, i16 [[CTTZ]]
229 ; ALL-NEXT: ret i16 [[SEL]]
231 %tobool = icmp eq i16 %A, 0
232 br i1 %tobool, label %cond.end, label %cond.true
234 cond.true: ; preds = %entry
235 %0 = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
238 cond.end: ; preds = %entry, %cond.true
239 %cond = phi i16 [ %0, %cond.true ], [ 15, %entry ]
244 declare i64 @llvm.ctlz.i64(i64, i1)
245 declare i32 @llvm.ctlz.i32(i32, i1)
246 declare i16 @llvm.ctlz.i16(i16, i1)
247 declare i64 @llvm.cttz.i64(i64, i1)
248 declare i32 @llvm.cttz.i32(i32, i1)
249 declare i16 @llvm.cttz.i16(i16, i1)