1 ; Ignore stderr, we expect warnings there
2 ; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
4 target datalayout = "E-p:64:64:64-p1:16:16:16-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
6 ; Simple case, argument translatable without changing the value
7 declare void @test1a(i8*)
9 define void @test1(i32* %A) {
10 ; CHECK-LABEL: @test1(
11 ; CHECK: %1 = bitcast i32* %A to i8*
12 ; CHECK: call void @test1a(i8* %1)
14 call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
19 ; Should not do because of change in address space of the parameter
20 define void @test1_as1_illegal(i32 addrspace(1)* %A) {
21 ; CHECK-LABEL: @test1_as1_illegal(
22 ; CHECK: call void bitcast
23 call void bitcast (void (i8*)* @test1a to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A)
27 ; Test1, but the argument has a different sized address-space
28 declare void @test1a_as1(i8 addrspace(1)*)
30 ; This one is OK to perform
31 define void @test1_as1(i32 addrspace(1)* %A) {
32 ; CHECK-LABEL: @test1_as1(
33 ; CHECK: %1 = bitcast i32 addrspace(1)* %A to i8 addrspace(1)*
34 ; CHECK: call void @test1a_as1(i8 addrspace(1)* %1)
36 call void bitcast (void (i8 addrspace(1)*)* @test1a_as1 to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A )
40 ; More complex case, translate argument because of resolution. This is safe
41 ; because we have the body of the function
42 define void @test2a(i8 %A) {
43 ; CHECK-LABEL: @test2a(
48 define i32 @test2(i32 %A) {
49 ; CHECK-LABEL: @test2(
50 ; CHECK: call void bitcast
52 call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
57 ; Resolving this should insert a cast from sbyte to int, following the C
59 define void @test3a(i8, ...) {unreachable }
61 define void @test3(i8 %A, i8 %B) {
62 ; CHECK-LABEL: @test3(
63 ; CHECK: %1 = zext i8 %B to i32
64 ; CHECK: call void (i8, ...) @test3a(i8 %A, i32 %1)
66 call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B)
70 ; test conversion of return value...
72 ; CHECK-LABEL: @test4a(
78 ; CHECK-LABEL: @test4(
79 ; CHECK: call i32 bitcast
80 %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1]
84 ; test conversion of return value... no value conversion occurs so we can do
85 ; this with just a prototype...
89 ; CHECK-LABEL: @test5(
90 ; CHECK: %X = call i32 @test5a()
92 %X = call i32 @test5a( ) ; <i32> [#uses=1]
96 ; test addition of new arguments...
97 declare i32 @test6a(i32)
100 ; CHECK-LABEL: @test6(
101 ; CHECK: %X = call i32 @test6a(i32 0)
103 %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
107 ; test removal of arguments, only can happen with a function body
108 define void @test7a() {
109 ; CHECK-LABEL: @test7a(
114 define void @test7() {
115 ; CHECK-LABEL: @test7(
116 ; CHECK: call void @test7a()
118 call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
124 declare void @test8a()
126 define i8* @test8() personality i32 (...)* @__gxx_personality_v0 {
127 ; CHECK-LABEL: @test8(
128 ; CHECK-NEXT: invoke void @test8a()
129 ; Don't turn this into "unreachable": the callee and caller don't agree in
130 ; calling conv, but the implementation of test8a may actually end up using the
131 ; right calling conv.
132 invoke void @test8a()
133 to label %invoke.cont unwind label %try.handler
135 invoke.cont: ; preds = %entry
138 try.handler: ; preds = %entry
139 %exn = landingpad {i8*, i32}
144 declare i32 @__gxx_personality_v0(...)
147 ; Don't turn this into a direct call, because test9x is just a prototype and
148 ; doing so will make it varargs.
150 declare i8* @test9x(i8*, i8*, ...) noredzone
151 define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
152 ; CHECK-LABEL: @test9
154 %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
156 ; CHECK-LABEL: @test9(
157 ; CHECK: call i8* bitcast
161 ; Parameter that's a vector of pointers
162 declare void @test10a(<2 x i8*>)
164 define void @test10(<2 x i32*> %A) {
165 ; CHECK-LABEL: @test10(
166 ; CHECK: %1 = bitcast <2 x i32*> %A to <2 x i8*>
167 ; CHECK: call void @test10a(<2 x i8*> %1)
169 call void bitcast (void (<2 x i8*>)* @test10a to void (<2 x i32*>)*)(<2 x i32*> %A)
173 ; Don't transform because different address spaces
174 declare void @test10a_mixed_as(<2 x i8 addrspace(1)*>)
176 define void @test10_mixed_as(<2 x i8*> %A) {
177 ; CHECK-LABEL: @test10_mixed_as(
178 ; CHECK: call void bitcast
179 call void bitcast (void (<2 x i8 addrspace(1)*>)* @test10a_mixed_as to void (<2 x i8*>)*)(<2 x i8*> %A)
183 ; Return type that's a pointer
184 define i8* @test11a() {
185 ret i8* zeroinitializer
188 define i32* @test11() {
189 ; CHECK-LABEL: @test11(
190 ; CHECK: %X = call i8* @test11a()
191 ; CHECK: %1 = bitcast i8* %X to i32*
192 %X = call i32* bitcast (i8* ()* @test11a to i32* ()*)()
196 ; Return type that's a pointer with a different address space
197 define i8 addrspace(1)* @test11a_mixed_as() {
198 ret i8 addrspace(1)* zeroinitializer
201 define i8* @test11_mixed_as() {
202 ; CHECK-LABEL: @test11_mixed_as(
203 ; CHECK: call i8* bitcast
204 %X = call i8* bitcast (i8 addrspace(1)* ()* @test11a_mixed_as to i8* ()*)()
208 ; Return type that's a vector of pointers
209 define <2 x i8*> @test12a() {
210 ret <2 x i8*> zeroinitializer
213 define <2 x i32*> @test12() {
214 ; CHECK-LABEL: @test12(
215 ; CHECK: %X = call <2 x i8*> @test12a()
216 ; CHECK: %1 = bitcast <2 x i8*> %X to <2 x i32*>
217 %X = call <2 x i32*> bitcast (<2 x i8*> ()* @test12a to <2 x i32*> ()*)()
221 define <2 x i8 addrspace(1)*> @test12a_mixed_as() {
222 ret <2 x i8 addrspace(1)*> zeroinitializer
225 define <2 x i8*> @test12_mixed_as() {
226 ; CHECK-LABEL: @test12_mixed_as(
227 ; CHECK: call <2 x i8*> bitcast
228 %X = call <2 x i8*> bitcast (<2 x i8 addrspace(1)*> ()* @test12a_mixed_as to <2 x i8*> ()*)()
233 ; Mix parameter that's a vector of integers and pointers of the same size
234 declare void @test13a(<2 x i64>)
236 define void @test13(<2 x i32*> %A) {
237 ; CHECK-LABEL: @test13(
238 ; CHECK: call void bitcast
239 call void bitcast (void (<2 x i64>)* @test13a to void (<2 x i32*>)*)(<2 x i32*> %A)
243 ; Mix parameter that's a vector of integers and pointers of the same
244 ; size, but the other way around
245 declare void @test14a(<2 x i8*>)
247 define void @test14(<2 x i64> %A) {
248 ; CHECK-LABEL: @test14(
249 ; CHECK: call void bitcast
250 call void bitcast (void (<2 x i8*>)* @test14a to void (<2 x i64>)*)(<2 x i64> %A)
255 ; Return type that's a vector
256 define <2 x i16> @test15a() {
257 ret <2 x i16> zeroinitializer
260 define i32 @test15() {
261 ; CHECK-LABEL: @test15(
262 ; CHECK: %X = call <2 x i16> @test15a()
263 ; CHECK: %1 = bitcast <2 x i16> %X to i32
264 %X = call i32 bitcast (<2 x i16> ()* @test15a to i32 ()*)( )
268 define i32 @test16a() {
272 define <2 x i16> @test16() {
273 ; CHECK-LABEL: @test16(
274 ; CHECK: %X = call i32 @test16a()
275 ; CHECK: %1 = bitcast i32 %X to <2 x i16>
276 %X = call <2 x i16> bitcast (i32 ()* @test16a to <2 x i16> ()*)( )
280 declare i32 @pr28655(i32 returned %V)
282 define i32 @test17() {
284 %C = call i32 @pr28655(i32 0)
287 ; CHECK-LABEL: @test17(
288 ; CHECK: call i32 @pr28655(i32 0)
291 define void @non_vararg(i8*, i32) {
295 define void @test_cast_to_vararg(i8* %this) {
296 ; CHECK-LABEL: test_cast_to_vararg
297 ; CHECK: call void @non_vararg(i8* %this, i32 42)
298 call void (i8*, ...) bitcast (void (i8*, i32)* @non_vararg to void (i8*, ...)*)(i8* %this, i32 42)