1; RUN: opt < %s -instcombine -S | FileCheck %s 2 3target datalayout = "e-p:32:32" 4target triple = "i686-pc-linux-gnu" 5 6define i32 @main() { 7; CHECK-LABEL: @main 8; CHECK: %[[call:.*]] = call i8* @ctime(i32* null) 9; CHECK: %[[cast:.*]] = ptrtoint i8* %[[call]] to i32 10; CHECK: ret i32 %[[cast]] 11entry: 12 %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null ) ; <i32> [#uses=1] 13 ret i32 %tmp 14} 15 16declare i8* @ctime(i32*) 17 18define internal { i8 } @foo(i32*) { 19entry: 20 ret { i8 } { i8 0 } 21} 22 23define void @test_struct_ret() { 24; CHECK-LABEL: @test_struct_ret 25; CHECK-NOT: bitcast 26entry: 27 %0 = call { i8 } bitcast ({ i8 } (i32*)* @foo to { i8 } (i16*)*)(i16* null) 28 ret void 29} 30 31declare i32 @fn1(i32) 32 33define i32 @test1(i32* %a) { 34; CHECK-LABEL: @test1 35; CHECK: %[[cast:.*]] = ptrtoint i32* %a to i32 36; CHECK-NEXT: %[[call:.*]] = tail call i32 @fn1(i32 %[[cast]]) 37; CHECK-NEXT: ret i32 %[[call]] 38entry: 39 %call = tail call i32 bitcast (i32 (i32)* @fn1 to i32 (i32*)*)(i32* %a) 40 ret i32 %call 41} 42 43declare i32 @fn2(i16) 44 45define i32 @test2(i32* %a) { 46; CHECK-LABEL: @test2 47; CHECK: %[[call:.*]] = tail call i32 bitcast (i32 (i16)* @fn2 to i32 (i32*)*)(i32* %a) 48; CHECK-NEXT: ret i32 %[[call]] 49entry: 50 %call = tail call i32 bitcast (i32 (i16)* @fn2 to i32 (i32*)*)(i32* %a) 51 ret i32 %call 52} 53 54declare i32 @fn3(i64) 55 56define i32 @test3(i32* %a) { 57; CHECK-LABEL: @test3 58; CHECK: %[[call:.*]] = tail call i32 bitcast (i32 (i64)* @fn3 to i32 (i32*)*)(i32* %a) 59; CHECK-NEXT: ret i32 %[[call]] 60entry: 61 %call = tail call i32 bitcast (i32 (i64)* @fn3 to i32 (i32*)*)(i32* %a) 62 ret i32 %call 63} 64 65declare i32 @fn4(i32) "thunk" 66 67define i32 @test4(i32* %a) { 68; CHECK-LABEL: @test4 69; CHECK: %[[call:.*]] = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a) 70; CHECK-NEXT: ret i32 %[[call]] 71entry: 72 %call = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a) 73 ret i32 %call 74} 75 76declare i1 @fn5({ i32, i32 }* byval({ i32, i32 }) align 4 %r) 77 78define i1 @test5() { 79; CHECK-LABEL: @test5 80; CHECK: %[[call:.*]] = call i1 bitcast (i1 ({ i32, i32 }*)* @fn5 to i1 (i32, i32)*)(i32 {{.*}}, i32 {{.*}}) 81; CHECK-NEXT: ret i1 %[[call]] 82 %1 = alloca { i32, i32 }, align 4 83 %2 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %1, i32 0, i32 0 84 %3 = load i32, i32* %2, align 4 85 %4 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %1, i32 0, i32 1 86 %5 = load i32, i32* %4, align 4 87 %6 = call i1 bitcast (i1 ({ i32, i32 }*)* @fn5 to i1 (i32, i32)*)(i32 %3, i32 %5) 88 ret i1 %6 89} 90