Skip to content

Commit 4749669

Browse files
committed
[InstCombine] auto-generate complete checks; NFC
llvm-svn: 305474
1 parent be2674a commit 4749669

File tree

1 file changed

+106
-50
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+106
-50
lines changed
Lines changed: 106 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
; Test that the ffs* library call simplifier works correctly.
22
;
3-
; RUN: opt < %s -instcombine -S | FileCheck %s
4-
; RUN: opt < %s -mtriple i386-pc-linux -instcombine -S | FileCheck %s -check-prefix=CHECK-FFS
5-
; RUN: opt -instcombine -mtriple=arm64-apple-ios9.0 -S %s | FileCheck --check-prefix=CHECK-FFS %s
6-
; RUN: opt -instcombine -mtriple=arm64-apple-tvos9.0 -S %s | FileCheck --check-prefix=CHECK-FFS %s
7-
; RUN: opt -instcombine -mtriple=thumbv7k-apple-watchos2.0 -S %s | FileCheck --check-prefix=CHECK-FFS %s
8-
; RUN: opt -instcombine -mtriple=x86_64-apple-macosx10.11 -S %s | FileCheck --check-prefix=CHECK-FFS %s
9-
; RUN: opt -instcombine -mtriple=x86_64-freebsd-gnu -S %s | FileCheck --check-prefix=CHECK-FFS %s
3+
; RUN: opt < %s -instcombine -S | FileCheck %s --check-prefix=ALL --check-prefix=GENERIC
4+
; RUN: opt < %s -instcombine -mtriple i386-pc-linux -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET
5+
; RUN: opt < %s -instcombine -mtriple=arm64-apple-ios9.0 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET
6+
; RUN: opt < %s -instcombine -mtriple=arm64-apple-tvos9.0 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET
7+
; RUN: opt < %s -instcombine -mtriple=thumbv7k-apple-watchos2.0 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET
8+
; RUN: opt < %s -instcombine -mtriple=x86_64-apple-macosx10.11 -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET
9+
; RUN: opt < %s -instcombine -mtriple=x86_64-freebsd-gnu -S | FileCheck %s --check-prefix=ALL --check-prefix=TARGET
1010

1111
declare i32 @ffs(i32)
1212
declare i32 @ffsl(i32)
@@ -15,123 +15,179 @@ declare i32 @ffsll(i64)
1515
; Check ffs(0) -> 0.
1616

1717
define i32 @test_simplify1() {
18-
; CHECK-LABEL: @test_simplify1(
18+
; ALL-LABEL: @test_simplify1(
19+
; ALL-NEXT: ret i32 0
20+
;
1921
%ret = call i32 @ffs(i32 0)
2022
ret i32 %ret
21-
; CHECK-NEXT: ret i32 0
2223
}
2324

2425
define i32 @test_simplify2() {
25-
; CHECK-FFS-LABEL: @test_simplify2(
26+
; GENERIC-LABEL: @test_simplify2(
27+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsl(i32 0)
28+
; GENERIC-NEXT: ret i32 [[RET]]
29+
;
30+
; TARGET-LABEL: @test_simplify2(
31+
; TARGET-NEXT: ret i32 0
32+
;
2633
%ret = call i32 @ffsl(i32 0)
2734
ret i32 %ret
28-
; CHECK-FFS-NEXT: ret i32 0
2935
}
3036

3137
define i32 @test_simplify3() {
32-
; CHECK-FFS-LABEL: @test_simplify3(
38+
; GENERIC-LABEL: @test_simplify3(
39+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 0)
40+
; GENERIC-NEXT: ret i32 [[RET]]
41+
;
42+
; TARGET-LABEL: @test_simplify3(
43+
; TARGET-NEXT: ret i32 0
44+
;
3345
%ret = call i32 @ffsll(i64 0)
3446
ret i32 %ret
35-
; CHECK-FFS-NEXT: ret i32 0
3647
}
3748

3849
; Check ffs(c) -> cttz(c) + 1, where 'c' is a constant.
3950

4051
define i32 @test_simplify4() {
41-
; CHECK-LABEL: @test_simplify4(
52+
; ALL-LABEL: @test_simplify4(
53+
; ALL-NEXT: ret i32 1
54+
;
4255
%ret = call i32 @ffs(i32 1)
4356
ret i32 %ret
44-
; CHECK-NEXT: ret i32 1
4557
}
4658

4759
define i32 @test_simplify5() {
48-
; CHECK-LABEL: @test_simplify5(
60+
; ALL-LABEL: @test_simplify5(
61+
; ALL-NEXT: ret i32 12
62+
;
4963
%ret = call i32 @ffs(i32 2048)
5064
ret i32 %ret
51-
; CHECK-NEXT: ret i32 12
5265
}
5366

5467
define i32 @test_simplify6() {
55-
; CHECK-LABEL: @test_simplify6(
68+
; ALL-LABEL: @test_simplify6(
69+
; ALL-NEXT: ret i32 17
70+
;
5671
%ret = call i32 @ffs(i32 65536)
5772
ret i32 %ret
58-
; CHECK-NEXT: ret i32 17
5973
}
6074

6175
define i32 @test_simplify7() {
62-
; CHECK-FFS-LABEL: @test_simplify7(
76+
; GENERIC-LABEL: @test_simplify7(
77+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsl(i32 65536)
78+
; GENERIC-NEXT: ret i32 [[RET]]
79+
;
80+
; TARGET-LABEL: @test_simplify7(
81+
; TARGET-NEXT: ret i32 17
82+
;
6383
%ret = call i32 @ffsl(i32 65536)
6484
ret i32 %ret
65-
; CHECK-FFS-NEXT: ret i32 17
6685
}
6786

6887
define i32 @test_simplify8() {
69-
; CHECK-FFS-LABEL: @test_simplify8(
88+
; GENERIC-LABEL: @test_simplify8(
89+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 1024)
90+
; GENERIC-NEXT: ret i32 [[RET]]
91+
;
92+
; TARGET-LABEL: @test_simplify8(
93+
; TARGET-NEXT: ret i32 11
94+
;
7095
%ret = call i32 @ffsll(i64 1024)
7196
ret i32 %ret
72-
; CHECK-FFS-NEXT: ret i32 11
7397
}
7498

7599
define i32 @test_simplify9() {
76-
; CHECK-FFS-LABEL: @test_simplify9(
100+
; GENERIC-LABEL: @test_simplify9(
101+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 65536)
102+
; GENERIC-NEXT: ret i32 [[RET]]
103+
;
104+
; TARGET-LABEL: @test_simplify9(
105+
; TARGET-NEXT: ret i32 17
106+
;
77107
%ret = call i32 @ffsll(i64 65536)
78108
ret i32 %ret
79-
; CHECK-FFS-NEXT: ret i32 17
80109
}
81110

82111
define i32 @test_simplify10() {
83-
; CHECK-FFS-LABEL: @test_simplify10(
112+
; GENERIC-LABEL: @test_simplify10(
113+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 17179869184)
114+
; GENERIC-NEXT: ret i32 [[RET]]
115+
;
116+
; TARGET-LABEL: @test_simplify10(
117+
; TARGET-NEXT: ret i32 35
118+
;
84119
%ret = call i32 @ffsll(i64 17179869184)
85120
ret i32 %ret
86-
; CHECK-FFS-NEXT: ret i32 35
87121
}
88122

89123
define i32 @test_simplify11() {
90-
; CHECK-FFS-LABEL: @test_simplify11(
124+
; GENERIC-LABEL: @test_simplify11(
125+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 281474976710656)
126+
; GENERIC-NEXT: ret i32 [[RET]]
127+
;
128+
; TARGET-LABEL: @test_simplify11(
129+
; TARGET-NEXT: ret i32 49
130+
;
91131
%ret = call i32 @ffsll(i64 281474976710656)
92132
ret i32 %ret
93-
; CHECK-FFS-NEXT: ret i32 49
94133
}
95134

96135
define i32 @test_simplify12() {
97-
; CHECK-FFS-LABEL: @test_simplify12(
136+
; GENERIC-LABEL: @test_simplify12(
137+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 1152921504606846976)
138+
; GENERIC-NEXT: ret i32 [[RET]]
139+
;
140+
; TARGET-LABEL: @test_simplify12(
141+
; TARGET-NEXT: ret i32 61
142+
;
98143
%ret = call i32 @ffsll(i64 1152921504606846976)
99144
ret i32 %ret
100-
; CHECK-FFS-NEXT: ret i32 61
101145
}
102146

103147
; Check ffs(x) -> x != 0 ? (i32)llvm.cttz(x) + 1 : 0.
104148

105149
define i32 @test_simplify13(i32 %x) {
106-
; CHECK-LABEL: @test_simplify13(
150+
; ALL-LABEL: @test_simplify13(
151+
; ALL-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 %x, i1 true)
152+
; ALL-NEXT: [[TMP1:%.*]] = add nuw nsw i32 [[CTTZ]], 1
153+
; ALL-NEXT: [[TMP2:%.*]] = icmp ne i32 %x, 0
154+
; ALL-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 0
155+
; ALL-NEXT: ret i32 [[TMP3]]
156+
;
107157
%ret = call i32 @ffs(i32 %x)
108-
; CHECK-NEXT: [[CTTZ:%[a-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %x, i1 true)
109-
; CHECK-NEXT: [[INC:%[a-z0-9]+]] = add nuw nsw i32 [[CTTZ]], 1
110-
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %x, 0
111-
; CHECK-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[INC]], i32 0
112158
ret i32 %ret
113-
; CHECK-NEXT: ret i32 [[RET]]
114159
}
115160

116161
define i32 @test_simplify14(i32 %x) {
117-
; CHECK-FFS-LABEL: @test_simplify14(
162+
; GENERIC-LABEL: @test_simplify14(
163+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsl(i32 %x)
164+
; GENERIC-NEXT: ret i32 [[RET]]
165+
;
166+
; TARGET-LABEL: @test_simplify14(
167+
; TARGET-NEXT: [[CTTZ:%.*]] = call i32 @llvm.cttz.i32(i32 %x, i1 true)
168+
; TARGET-NEXT: [[TMP1:%.*]] = add nuw nsw i32 [[CTTZ]], 1
169+
; TARGET-NEXT: [[TMP2:%.*]] = icmp ne i32 %x, 0
170+
; TARGET-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 0
171+
; TARGET-NEXT: ret i32 [[TMP3]]
172+
;
118173
%ret = call i32 @ffsl(i32 %x)
119-
; CHECK-FFS-NEXT: [[CTTZ:%[a-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %x, i1 true)
120-
; CHECK-FFS-NEXT: [[INC:%[a-z0-9]+]] = add nuw nsw i32 [[CTTZ]], 1
121-
; CHECK-FFS-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %x, 0
122-
; CHECK-FFS-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[INC]], i32 0
123174
ret i32 %ret
124-
; CHECK-FFS-NEXT: ret i32 [[RET]]
125175
}
126176

127177
define i32 @test_simplify15(i64 %x) {
128-
; CHECK-FFS-LABEL: @test_simplify15(
178+
; GENERIC-LABEL: @test_simplify15(
179+
; GENERIC-NEXT: [[RET:%.*]] = call i32 @ffsll(i64 %x)
180+
; GENERIC-NEXT: ret i32 [[RET]]
181+
;
182+
; TARGET-LABEL: @test_simplify15(
183+
; TARGET-NEXT: [[CTTZ:%.*]] = call i64 @llvm.cttz.i64(i64 %x, i1 true)
184+
; TARGET-NEXT: [[TMP1:%.*]] = add nuw nsw i64 [[CTTZ]], 1
185+
; TARGET-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32
186+
; TARGET-NEXT: [[TMP3:%.*]] = icmp ne i64 %x, 0
187+
; TARGET-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 0
188+
; TARGET-NEXT: ret i32 [[TMP4]]
189+
;
129190
%ret = call i32 @ffsll(i64 %x)
130-
; CHECK-FFS-NEXT: [[CTTZ:%[a-z0-9]+]] = call i64 @llvm.cttz.i64(i64 %x, i1 true)
131-
; CHECK-FFS-NEXT: [[INC:%[a-z0-9]+]] = add nuw nsw i64 [[CTTZ]], 1
132-
; CHECK-FFS-NEXT: [[TRUNC:%[a-z0-9]+]] = trunc i64 [[INC]] to i32
133-
; CHECK-FFS-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i64 %x, 0
134-
; CHECK-FFS-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[TRUNC]], i32 0
135191
ret i32 %ret
136-
; CHECK-FFS-NEXT: ret i32 [[RET]]
137192
}
193+

0 commit comments

Comments
 (0)