1+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
12; RUN: opt < %s -instcombine -S | FileCheck %s
23
3- ; CHECK-LABEL: test1
4- ; CHECK: ret i1 true
54define i1 @test1 (i8 %A ) {
5+ ; CHECK-LABEL: @test1(
6+ ; CHECK-NEXT: ret i1 true
7+ ;
68 %B = sitofp i8 %A to double
79 %C = fcmp ult double %B , 128 .0
810 ret i1 %C
911}
1012
11- ; CHECK-LABEL: test2
12- ; CHECK: ret i1 true
1313define i1 @test2 (i8 %A ) {
14+ ; CHECK-LABEL: @test2(
15+ ; CHECK-NEXT: ret i1 true
16+ ;
1417 %B = sitofp i8 %A to double
1518 %C = fcmp ugt double %B , -128 .1
1619 ret i1 %C
1720}
1821
19- ; CHECK-LABEL: test3
20- ; CHECK: ret i1 true
2122define i1 @test3 (i8 %A ) {
23+ ; CHECK-LABEL: @test3(
24+ ; CHECK-NEXT: ret i1 true
25+ ;
2226 %B = sitofp i8 %A to double
2327 %C = fcmp ule double %B , 127 .0
2428 ret i1 %C
2529}
2630
27- ; CHECK-LABEL: test4
28- ; CHECK: icmp ne i8 %A, 127
29- ; CHECK-NEXT: ret i1
3031define i1 @test4 (i8 %A ) {
32+ ; CHECK-LABEL: @test4(
33+ ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A:%.*]], 127
34+ ; CHECK-NEXT: ret i1 [[C]]
35+ ;
3136 %B = sitofp i8 %A to double
3237 %C = fcmp ult double %B , 127 .0
3338 ret i1 %C
3439}
3540
36- ; CHECK-LABEL: test5
37- ; CHECK: ret i32
3841define i32 @test5 (i32 %A ) {
42+ ; CHECK-LABEL: @test5(
43+ ; CHECK-NEXT: ret i32 [[A:%.*]]
44+ ;
3945 %B = sitofp i32 %A to double
4046 %C = fptosi double %B to i32
4147 %D = uitofp i32 %C to double
4248 %E = fptoui double %D to i32
4349 ret i32 %E
4450}
4551
46- ; CHECK-LABEL: test6
47- ; CHECK: and i32 %A, 39
48- ; CHECK-NEXT: ret i32
4952define i32 @test6 (i32 %A ) {
53+ ; CHECK-LABEL: @test6(
54+ ; CHECK-NEXT: [[ADDCONV:%.*]] = and i32 [[A:%.*]], 39
55+ ; CHECK-NEXT: ret i32 [[ADDCONV]]
56+ ;
5057 %B = and i32 %A , 7
5158 %C = and i32 %A , 32
5259 %D = sitofp i32 %B to double
@@ -56,129 +63,156 @@ define i32 @test6(i32 %A) {
5663 ret i32 %G
5764}
5865
59- ; CHECK-LABEL: test7
60- ; CHECK: ret i32
61- define i32 @test7 (i32 %A ) nounwind {
66+ define i32 @test7 (i32 %A ) {
67+ ; CHECK-LABEL: @test7(
68+ ; CHECK-NEXT: ret i32 [[A:%.*]]
69+ ;
6270 %B = sitofp i32 %A to double
6371 %C = fptoui double %B to i32
6472 ret i32 %C
6573}
6674
67- ; CHECK-LABEL: test8
68- ; CHECK: ret i32
69- define i32 @test8 (i32 %A ) nounwind {
75+ define i32 @test8 (i32 %A ) {
76+ ; CHECK-LABEL: @test8(
77+ ; CHECK-NEXT: ret i32 [[A:%.*]]
78+ ;
7079 %B = uitofp i32 %A to double
7180 %C = fptosi double %B to i32
7281 ret i32 %C
7382}
7483
75- ; CHECK-LABEL: test9
76- ; CHECK: zext i8
77- ; CHECK-NEXT: ret i32
78- define i32 @test9 (i8 %A ) nounwind {
84+ define i32 @test9 (i8 %A ) {
85+ ; CHECK-LABEL: @test9(
86+ ; CHECK-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i32
87+ ; CHECK-NEXT: ret i32 [[C]]
88+ ;
7989 %B = sitofp i8 %A to float
8090 %C = fptoui float %B to i32
8191 ret i32 %C
8292}
8393
84- ; CHECK-LABEL: test10
85- ; CHECK: sext i8
86- ; CHECK-NEXT: ret i32
87- define i32 @test10 (i8 %A ) nounwind {
94+ define i32 @test10 (i8 %A ) {
95+ ; CHECK-LABEL: @test10(
96+ ; CHECK-NEXT: [[C:%.*]] = sext i8 [[A:%.*]] to i32
97+ ; CHECK-NEXT: ret i32 [[C]]
98+ ;
8899 %B = sitofp i8 %A to float
89100 %C = fptosi float %B to i32
90101 ret i32 %C
91102}
92103
93104; If the input value is outside of the range of the output cast, it's
94105; undefined behavior, so we can assume it fits.
95- ; CHECK-LABEL: test11
96- ; CHECK: trunc
97- ; CHECK-NEXT: ret i8
98- define i8 @test11 (i32 %A ) nounwind {
106+
107+ define i8 @test11 (i32 %A ) {
108+ ; CHECK-LABEL: @test11(
109+ ; CHECK-NEXT: [[C:%.*]] = trunc i32 [[A:%.*]] to i8
110+ ; CHECK-NEXT: ret i8 [[C]]
111+ ;
99112 %B = sitofp i32 %A to float
100113 %C = fptosi float %B to i8
101114 ret i8 %C
102115}
103116
104117; If the input value is negative, it'll be outside the range of the
105118; output cast, and thus undefined behavior.
106- ; CHECK-LABEL: test12
107- ; CHECK: zext i8
108- ; CHECK-NEXT: ret i32
109- define i32 @test12 (i8 %A ) nounwind {
119+
120+ define i32 @test12 (i8 %A ) {
121+ ; CHECK-LABEL: @test12(
122+ ; CHECK-NEXT: [[C:%.*]] = zext i8 [[A:%.*]] to i32
123+ ; CHECK-NEXT: ret i32 [[C]]
124+ ;
110125 %B = sitofp i8 %A to float
111126 %C = fptoui float %B to i32
112127 ret i32 %C
113128}
114129
115130; This can't fold because the 25-bit input doesn't fit in the mantissa.
116- ; CHECK-LABEL: test13
117- ; CHECK: uitofp
118- ; CHECK-NEXT: fptoui
119- define i32 @test13 (i25 %A ) nounwind {
131+
132+ define i32 @test13 (i25 %A ) {
133+ ; CHECK-LABEL: @test13(
134+ ; CHECK-NEXT: [[B:%.*]] = uitofp i25 [[A:%.*]] to float
135+ ; CHECK-NEXT: [[C:%.*]] = fptoui float [[B]] to i32
136+ ; CHECK-NEXT: ret i32 [[C]]
137+ ;
120138 %B = uitofp i25 %A to float
121139 %C = fptoui float %B to i32
122140 ret i32 %C
123141}
124142
125143; But this one can.
126- ; CHECK-LABEL: test14
127- ; CHECK: zext i24
128- ; CHECK-NEXT: ret i32
129- define i32 @test14 (i24 %A ) nounwind {
144+
145+ define i32 @test14 (i24 %A ) {
146+ ; CHECK-LABEL: @test14(
147+ ; CHECK-NEXT: [[C:%.*]] = zext i24 [[A:%.*]] to i32
148+ ; CHECK-NEXT: ret i32 [[C]]
149+ ;
130150 %B = uitofp i24 %A to float
131151 %C = fptoui float %B to i32
132152 ret i32 %C
133153}
134154
135155; And this one can too.
136- ; CHECK-LABEL: test15
137- ; CHECK: trunc i32
138- ; CHECK-NEXT: ret i24
139- define i24 @test15 (i32 %A ) nounwind {
156+
157+ define i24 @test15 (i32 %A ) {
158+ ; CHECK-LABEL: @test15(
159+ ; CHECK-NEXT: [[C:%.*]] = trunc i32 [[A:%.*]] to i24
160+ ; CHECK-NEXT: ret i24 [[C]]
161+ ;
140162 %B = uitofp i32 %A to float
141163 %C = fptoui float %B to i24
142164 ret i24 %C
143165}
144166
145- ; This can fold because the 25-bit input is signed and we disard the sign bit.
146- ; CHECK-LABEL: test16
147- ; CHECK: zext
148- define i32 @test16 (i25 %A ) nounwind {
149- %B = sitofp i25 %A to float
150- %C = fptoui float %B to i32
151- ret i32 %C
167+ ; This can fold because the 25-bit input is signed and we discard the sign bit.
168+
169+ define i32 @test16 (i25 %A ) {
170+ ; CHECK-LABEL: @test16(
171+ ; CHECK-NEXT: [[C:%.*]] = zext i25 [[A:%.*]] to i32
172+ ; CHECK-NEXT: ret i32 [[C]]
173+ ;
174+ %B = sitofp i25 %A to float
175+ %C = fptoui float %B to i32
176+ ret i32 %C
152177}
153178
154179; This can't fold because the 26-bit input won't fit the mantissa
155- ; even after disarding the signed bit.
156- ; CHECK-LABEL: test17
157- ; CHECK: sitofp
158- ; CHECK-NEXT: fptoui
159- define i32 @test17 (i26 %A ) nounwind {
160- %B = sitofp i26 %A to float
161- %C = fptoui float %B to i32
162- ret i32 %C
180+ ; even after discarding the signed bit.
181+
182+ define i32 @test17 (i26 %A ) {
183+ ; CHECK-LABEL: @test17(
184+ ; CHECK-NEXT: [[B:%.*]] = sitofp i26 [[A:%.*]] to float
185+ ; CHECK-NEXT: [[C:%.*]] = fptoui float [[B]] to i32
186+ ; CHECK-NEXT: ret i32 [[C]]
187+ ;
188+ %B = sitofp i26 %A to float
189+ %C = fptoui float %B to i32
190+ ret i32 %C
163191}
164192
165- ; This can fold because the 54-bit output is signed and we disard the sign bit.
166- ; CHECK-LABEL: test18
167- ; CHECK: trunc
168- define i54 @test18 (i64 %A ) nounwind {
169- %B = sitofp i64 %A to double
170- %C = fptosi double %B to i54
171- ret i54 %C
193+ ; This can fold because the 54-bit output is signed and we discard the sign bit.
194+
195+ define i54 @test18 (i64 %A ) {
196+ ; CHECK-LABEL: @test18(
197+ ; CHECK-NEXT: [[C:%.*]] = trunc i64 [[A:%.*]] to i54
198+ ; CHECK-NEXT: ret i54 [[C]]
199+ ;
200+ %B = sitofp i64 %A to double
201+ %C = fptosi double %B to i54
202+ ret i54 %C
172203}
173204
174205; This can't fold because the 55-bit output won't fit the mantissa
175- ; even after disarding the sign bit.
176- ; CHECK-LABEL: test19
177- ; CHECK: sitofp
178- ; CHECK-NEXT: fptosi
179- define i55 @test19 (i64 %A ) nounwind {
180- %B = sitofp i64 %A to double
181- %C = fptosi double %B to i55
182- ret i55 %C
206+ ; even after discarding the sign bit.
207+
208+ define i55 @test19 (i64 %A ) {
209+ ; CHECK-LABEL: @test19(
210+ ; CHECK-NEXT: [[B:%.*]] = sitofp i64 [[A:%.*]] to double
211+ ; CHECK-NEXT: [[C:%.*]] = fptosi double [[B]] to i55
212+ ; CHECK-NEXT: ret i55 [[C]]
213+ ;
214+ %B = sitofp i64 %A to double
215+ %C = fptosi double %B to i55
216+ ret i55 %C
183217}
184218
0 commit comments