Disable InstCombine unsafe folding bitcasts of calls w/ varargs.
[oota-llvm.git] / test / Transforms / InstCombine / call.ll
1 ; Ignore stderr, we expect warnings there
2 ; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
3
4 target datalayout = "E-p:64:64:64-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"
5
6 ; Simple case, argument translatable without changing the value
7 declare void @test1a(i8*)
8
9 define void @test1(i32* %A) {
10         call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
11         ret void
12 ; CHECK: %1 = bitcast i32* %A to i8*
13 ; CHECK: call void @test1a(i8* %1)
14 ; CHECK: ret void
15 }
16
17 ; More complex case, translate argument because of resolution.  This is safe 
18 ; because we have the body of the function
19 define void @test2a(i8 %A) {
20         ret void
21 ; CHECK: ret void
22 }
23
24 define i32 @test2(i32 %A) {
25         call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
26         ret i32 %A
27 ; CHECK: %1 = trunc i32 %A to i8
28 ; CHECK: call void @test2a(i8 %1)
29 ; CHECK: ret i32 %A
30 }
31
32
33 ; test conversion of return value...
34 define i8 @test4a() {
35         ret i8 0
36 ; CHECK: ret i8 0
37 }
38
39 define i32 @test4() {
40         %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( )            ; <i32> [#uses=1]
41         ret i32 %X
42 ; CHECK: %X = call i8 @test4a()
43 ; CHECK: %1 = zext i8 %X to i32
44 ; CHECK: ret i32 %1
45 }
46
47
48 ; test conversion of return value... no value conversion occurs so we can do 
49 ; this with just a prototype...
50 declare i32 @test5a()
51
52 define i32 @test5() {
53         %X = call i32 @test5a( )                ; <i32> [#uses=1]
54         ret i32 %X
55 ; CHECK: %X = call i32 @test5a()
56 ; CHECK: ret i32 %X
57 }
58
59
60 ; test addition of new arguments...
61 declare i32 @test6a(i32)
62
63 define i32 @test6() {
64         %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
65         ret i32 %X
66 ; CHECK: %X = call i32 @test6a(i32 0)
67 ; CHECK: ret i32 %X
68 }
69
70
71 ; test removal of arguments, only can happen with a function body
72 define void @test7a() {
73         ret void
74 ; CHECK: ret void
75 }
76
77 define void @test7() {
78         call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
79         ret void
80 ; CHECK: call void @test7a()
81 ; CHECK: ret void
82 }
83
84
85 ; rdar://7590304
86 declare void @test8a()
87
88 define i8* @test8() {
89   invoke void @test8a()
90           to label %invoke.cont unwind label %try.handler
91
92 invoke.cont:                                      ; preds = %entry
93   unreachable
94
95 try.handler:                                      ; preds = %entry
96   %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
97             cleanup
98   ret i8* null
99 }
100
101 declare i32 @__gxx_personality_v0(...)
102
103 ; Don't turn this into "unreachable": the callee and caller don't agree in
104 ; calling conv, but the implementation of test8a may actually end up using the
105 ; right calling conv.
106 ; CHECK: @test8() {
107 ; CHECK-NEXT: invoke void @test8a()
108
109
110
111 ; Don't turn this into a direct call, because test9x is just a prototype and 
112 ; doing so will make it varargs.
113 ; rdar://9038601
114 declare i8* @test9x(i8*, i8*, ...) noredzone
115 define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
116 entry:
117   %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
118   ret i8* %call
119 ; CHECK: @test9(
120 ; CHECK: call i8* bitcast
121 }
122