Change behavior of calling bitcasted alias functions.
[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 ; CHECK-LABEL: @test1(
11 ; CHECK: %1 = bitcast i32* %A to i8*
12 ; CHECK: call void @test1a(i8* %1)
13 ; CHECK: ret void
14   call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
15   ret void
16 }
17
18 ; More complex case, translate argument because of resolution.  This is safe
19 ; because we have the body of the function
20 define void @test2a(i8 %A) {
21 ; CHECK-LABEL: @test2a(
22 ; CHECK: ret void
23   ret void
24 }
25
26 define i32 @test2(i32 %A) {
27 ; CHECK-LABEL: @test2(
28 ; CHECK: call void bitcast
29 ; CHECK: ret i32 %A
30   call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
31   ret i32 %A
32 }
33
34
35 ; Resolving this should insert a cast from sbyte to int, following the C
36 ; promotion rules.
37 define void @test3a(i8, ...) {unreachable }
38
39 define void @test3(i8 %A, i8 %B) {
40 ; CHECK-LABEL: @test3(
41 ; CHECK: %1 = zext i8 %B to i32
42 ; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %1)
43 ; CHECK: ret void
44   call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B)
45   ret void
46 }
47
48 ; test conversion of return value...
49 define i8 @test4a() {
50 ; CHECK-LABEL: @test4a(
51 ; CHECK: ret i8 0
52   ret i8 0
53 }
54
55 define i32 @test4() {
56 ; CHECK-LABEL: @test4(
57 ; CHECK: call i32 bitcast
58   %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( )            ; <i32> [#uses=1]
59   ret i32 %X
60 }
61
62 ; test conversion of return value... no value conversion occurs so we can do
63 ; this with just a prototype...
64 declare i32 @test5a()
65
66 define i32 @test5() {
67 ; CHECK-LABEL: @test5(
68 ; CHECK: %X = call i32 @test5a()
69 ; CHECK: ret i32 %X
70   %X = call i32 @test5a( )                ; <i32> [#uses=1]
71   ret i32 %X
72 }
73
74 ; test addition of new arguments...
75 declare i32 @test6a(i32)
76
77 define i32 @test6() {
78 ; CHECK-LABEL: @test6(
79 ; CHECK: %X = call i32 @test6a(i32 0)
80 ; CHECK: ret i32 %X
81   %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
82   ret i32 %X
83 }
84
85 ; test removal of arguments, only can happen with a function body
86 define void @test7a() {
87 ; CHECK-LABEL: @test7a(
88 ; CHECK: ret void
89   ret void
90 }
91
92 define void @test7() {
93 ; CHECK-LABEL: @test7(
94 ; CHECK: call void @test7a()
95 ; CHECK: ret void
96   call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
97   ret void
98 }
99
100
101 ; rdar://7590304
102 declare void @test8a()
103
104 define i8* @test8() {
105 ; CHECK-LABEL: @test8(
106 ; CHECK-NEXT: invoke void @test8a()
107 ; Don't turn this into "unreachable": the callee and caller don't agree in
108 ; calling conv, but the implementation of test8a may actually end up using the
109 ; right calling conv.
110   invoke void @test8a()
111           to label %invoke.cont unwind label %try.handler
112
113 invoke.cont:                                      ; preds = %entry
114   unreachable
115
116 try.handler:                                      ; preds = %entry
117   %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
118             cleanup
119   ret i8* null
120 }
121
122 declare i32 @__gxx_personality_v0(...)
123
124
125 ; Don't turn this into a direct call, because test9x is just a prototype and
126 ; doing so will make it varargs.
127 ; rdar://9038601
128 declare i8* @test9x(i8*, i8*, ...) noredzone
129 define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
130 ; CHECK-LABEL: @test9
131 entry:
132   %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
133   ret i8* %call
134 ; CHECK-LABEL: @test9(
135 ; CHECK: call i8* bitcast
136 }
137