2008-06-10 18:13:38 +02:00
|
|
|
; Ignore stderr, we expect warnings there
|
2009-10-12 10:51:28 +02:00
|
|
|
; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
|
2003-06-19 00:48:11 +02:00
|
|
|
|
2009-11-03 16:29:06 +01:00
|
|
|
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"
|
2003-06-19 00:48:11 +02:00
|
|
|
|
|
|
|
; Simple case, argument translatable without changing the value
|
2008-03-25 05:26:08 +01:00
|
|
|
declare void @test1a(i8*)
|
|
|
|
|
|
|
|
define void @test1(i32* %A) {
|
|
|
|
call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
|
2003-06-19 00:48:11 +02:00
|
|
|
ret void
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: %tmp = bitcast i32* %A to i8*
|
|
|
|
; CHECK: call void @test1a(i8* %tmp)
|
|
|
|
; CHECK: ret void
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
; More complex case, translate argument because of resolution. This is safe
|
|
|
|
; because we have the body of the function
|
2008-03-25 05:26:08 +01:00
|
|
|
define void @test2a(i8 %A) {
|
|
|
|
ret void
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: ret void
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 05:26:08 +01:00
|
|
|
define i32 @test2(i32 %A) {
|
|
|
|
call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
|
|
|
|
ret i32 %A
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: %tmp = trunc i32 %A to i8
|
|
|
|
; CHECK: call void @test2a(i8 %tmp)
|
|
|
|
; CHECK: ret i32 %A
|
2008-03-25 05:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-19 00:48:11 +02:00
|
|
|
; Resolving this should insert a cast from sbyte to int, following the C
|
|
|
|
; promotion rules.
|
2011-02-24 06:10:56 +01:00
|
|
|
define void @test3a(i8, ...) {unreachable }
|
2008-03-25 05:26:08 +01:00
|
|
|
|
|
|
|
define void @test3(i8 %A, i8 %B) {
|
|
|
|
call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B
|
|
|
|
)
|
2003-06-19 00:48:11 +02:00
|
|
|
ret void
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: %tmp = zext i8 %B to i32
|
|
|
|
; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %tmp)
|
|
|
|
; CHECK: ret void
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 05:26:08 +01:00
|
|
|
|
2003-06-19 00:48:11 +02:00
|
|
|
; test conversion of return value...
|
2008-03-25 05:26:08 +01:00
|
|
|
define i8 @test4a() {
|
|
|
|
ret i8 0
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: ret i8 0
|
2008-03-25 05:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test4() {
|
|
|
|
%X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1]
|
|
|
|
ret i32 %X
|
2011-05-18 03:28:27 +02:00
|
|
|
; CHECK: %X = call i8 @test4a()
|
|
|
|
; CHECK: %tmp = zext i8 %X to i32
|
2009-10-12 11:01:26 +02:00
|
|
|
; CHECK: ret i32 %tmp
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 05:26:08 +01:00
|
|
|
|
2003-06-19 00:48:11 +02:00
|
|
|
; test conversion of return value... no value conversion occurs so we can do
|
|
|
|
; this with just a prototype...
|
2008-03-25 05:26:08 +01:00
|
|
|
declare i32 @test5a()
|
|
|
|
|
|
|
|
define i32 @test5() {
|
|
|
|
%X = call i32 @test5a( ) ; <i32> [#uses=1]
|
|
|
|
ret i32 %X
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: %X = call i32 @test5a()
|
|
|
|
; CHECK: ret i32 %X
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 05:26:08 +01:00
|
|
|
|
2003-06-19 00:48:11 +02:00
|
|
|
; test addition of new arguments...
|
2008-03-25 05:26:08 +01:00
|
|
|
declare i32 @test6a(i32)
|
|
|
|
|
|
|
|
define i32 @test6() {
|
2010-02-01 19:11:34 +01:00
|
|
|
%X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
|
2008-03-25 05:26:08 +01:00
|
|
|
ret i32 %X
|
2011-05-18 03:28:27 +02:00
|
|
|
; CHECK: %X = call i32 @test6a(i32 0)
|
|
|
|
; CHECK: ret i32 %X
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 05:26:08 +01:00
|
|
|
|
2003-06-19 00:48:11 +02:00
|
|
|
; test removal of arguments, only can happen with a function body
|
2008-03-25 05:26:08 +01:00
|
|
|
define void @test7a() {
|
2003-06-19 00:48:11 +02:00
|
|
|
ret void
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: ret void
|
2003-06-19 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-25 05:26:08 +01:00
|
|
|
define void @test7() {
|
|
|
|
call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
|
|
|
|
ret void
|
2009-10-12 10:46:47 +02:00
|
|
|
; CHECK: call void @test7a()
|
|
|
|
; CHECK: ret void
|
2008-03-25 05:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-01 19:11:34 +01:00
|
|
|
; rdar://7590304
|
|
|
|
declare void @test8a()
|
|
|
|
|
|
|
|
define i8* @test8() {
|
2010-06-17 17:18:27 +02:00
|
|
|
invoke void @test8a()
|
2010-02-01 19:11:34 +01:00
|
|
|
to label %invoke.cont unwind label %try.handler
|
|
|
|
|
|
|
|
invoke.cont: ; preds = %entry
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
try.handler: ; preds = %entry
|
|
|
|
ret i8* null
|
|
|
|
}
|
|
|
|
|
|
|
|
; Don't turn this into "unreachable": the callee and caller don't agree in
|
|
|
|
; calling conv, but the implementation of test8a may actually end up using the
|
|
|
|
; right calling conv.
|
|
|
|
; CHECK: @test8() {
|
2010-06-17 17:18:27 +02:00
|
|
|
; CHECK-NEXT: invoke void @test8a()
|
2010-02-01 19:11:34 +01:00
|
|
|
|
2011-02-24 06:10:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
; Don't turn this into a direct call, because test9x is just a prototype and
|
|
|
|
; doing so will make it varargs.
|
|
|
|
; rdar://9038601
|
|
|
|
declare i8* @test9x(i8*, i8*, ...) noredzone
|
|
|
|
define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
|
|
|
|
entry:
|
|
|
|
%call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
|
|
|
|
ret i8* %call
|
|
|
|
; CHECK: @test9(
|
|
|
|
; CHECK: call i8* bitcast
|
|
|
|
}
|
|
|
|
|