Use BranchProbability instead of floating points in IfConverter.
[llvm/stm8.git] / test / Transforms / InstCombine / call.ll
blobd0848739cdcc22f1cc9e9f27b17624d67b7fe18e
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-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         call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
11         ret void
12 ; CHECK: %tmp = bitcast i32* %A to i8*
13 ; CHECK: call void @test1a(i8* %tmp)
14 ; CHECK: ret void
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
24 define i32 @test2(i32 %A) {
25         call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
26         ret i32 %A
27 ; CHECK: %tmp = trunc i32 %A to i8
28 ; CHECK: call void @test2a(i8 %tmp)
29 ; CHECK: ret i32 %A
33 ; Resolving this should insert a cast from sbyte to int, following the C 
34 ; promotion rules.
35 define void @test3a(i8, ...) {unreachable }
37 define void @test3(i8 %A, i8 %B) {
38         call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B 
40         ret void
41 ; CHECK: %tmp = zext i8 %B to i32
42 ; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %tmp)
43 ; CHECK: ret void
47 ; test conversion of return value...
48 define i8 @test4a() {
49         ret i8 0
50 ; CHECK: ret i8 0
53 define i32 @test4() {
54         %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( )            ; <i32> [#uses=1]
55         ret i32 %X
56 ; CHECK: %X = call i8 @test4a()
57 ; CHECK: %tmp = zext i8 %X to i32
58 ; CHECK: ret i32 %tmp
62 ; test conversion of return value... no value conversion occurs so we can do 
63 ; this with just a prototype...
64 declare i32 @test5a()
66 define i32 @test5() {
67         %X = call i32 @test5a( )                ; <i32> [#uses=1]
68         ret i32 %X
69 ; CHECK: %X = call i32 @test5a()
70 ; CHECK: ret i32 %X
74 ; test addition of new arguments...
75 declare i32 @test6a(i32)
77 define i32 @test6() {
78         %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
79         ret i32 %X
80 ; CHECK: %X = call i32 @test6a(i32 0)
81 ; CHECK: ret i32 %X
85 ; test removal of arguments, only can happen with a function body
86 define void @test7a() {
87         ret void
88 ; CHECK: ret void
91 define void @test7() {
92         call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
93         ret void
94 ; CHECK: call void @test7a()
95 ; CHECK: ret void
99 ; rdar://7590304
100 declare void @test8a()
102 define i8* @test8() {
103   invoke void @test8a()
104           to label %invoke.cont unwind label %try.handler
106 invoke.cont:                                      ; preds = %entry
107   unreachable
109 try.handler:                                      ; preds = %entry
110   ret i8* null
113 ; Don't turn this into "unreachable": the callee and caller don't agree in
114 ; calling conv, but the implementation of test8a may actually end up using the
115 ; right calling conv.
116 ; CHECK: @test8() {
117 ; CHECK-NEXT: invoke void @test8a()
121 ; Don't turn this into a direct call, because test9x is just a prototype and 
122 ; doing so will make it varargs.
123 ; rdar://9038601
124 declare i8* @test9x(i8*, i8*, ...) noredzone
125 define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
126 entry:
127   %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
128   ret i8* %call
129 ; CHECK: @test9(
130 ; CHECK: call i8* bitcast