1*9880d681SAndroid Build Coastguard Worker; Ignore stderr, we expect warnings there 2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workertarget datalayout = "E-p:64:64:64-p1:16:16:16-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*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker; Simple case, argument translatable without changing the value 7*9880d681SAndroid Build Coastguard Workerdeclare void @test1a(i8*) 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32* %A) { 10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1( 11*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast i32* %A to i8* 12*9880d681SAndroid Build Coastguard Worker; CHECK: call void @test1a(i8* %1) 13*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 14*9880d681SAndroid Build Coastguard Worker call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A ) 15*9880d681SAndroid Build Coastguard Worker ret void 16*9880d681SAndroid Build Coastguard Worker} 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker; Should not do because of change in address space of the parameter 20*9880d681SAndroid Build Coastguard Workerdefine void @test1_as1_illegal(i32 addrspace(1)* %A) { 21*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1_as1_illegal( 22*9880d681SAndroid Build Coastguard Worker; CHECK: call void bitcast 23*9880d681SAndroid Build Coastguard Worker call void bitcast (void (i8*)* @test1a to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A) 24*9880d681SAndroid Build Coastguard Worker ret void 25*9880d681SAndroid Build Coastguard Worker} 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker; Test1, but the argument has a different sized address-space 28*9880d681SAndroid Build Coastguard Workerdeclare void @test1a_as1(i8 addrspace(1)*) 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker; This one is OK to perform 31*9880d681SAndroid Build Coastguard Workerdefine void @test1_as1(i32 addrspace(1)* %A) { 32*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1_as1( 33*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast i32 addrspace(1)* %A to i8 addrspace(1)* 34*9880d681SAndroid Build Coastguard Worker; CHECK: call void @test1a_as1(i8 addrspace(1)* %1) 35*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 36*9880d681SAndroid Build Coastguard Worker call void bitcast (void (i8 addrspace(1)*)* @test1a_as1 to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A ) 37*9880d681SAndroid Build Coastguard Worker ret void 38*9880d681SAndroid Build Coastguard Worker} 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker; More complex case, translate argument because of resolution. This is safe 41*9880d681SAndroid Build Coastguard Worker; because we have the body of the function 42*9880d681SAndroid Build Coastguard Workerdefine void @test2a(i8 %A) { 43*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2a( 44*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 45*9880d681SAndroid Build Coastguard Worker ret void 46*9880d681SAndroid Build Coastguard Worker} 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Workerdefine i32 @test2(i32 %A) { 49*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2( 50*9880d681SAndroid Build Coastguard Worker; CHECK: call void bitcast 51*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 %A 52*9880d681SAndroid Build Coastguard Worker call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A ) 53*9880d681SAndroid Build Coastguard Worker ret i32 %A 54*9880d681SAndroid Build Coastguard Worker} 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker; Resolving this should insert a cast from sbyte to int, following the C 58*9880d681SAndroid Build Coastguard Worker; promotion rules. 59*9880d681SAndroid Build Coastguard Workerdefine void @test3a(i8, ...) {unreachable } 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Workerdefine void @test3(i8 %A, i8 %B) { 62*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test3( 63*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = zext i8 %B to i32 64*9880d681SAndroid Build Coastguard Worker; CHECK: call void (i8, ...) @test3a(i8 %A, i32 %1) 65*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 66*9880d681SAndroid Build Coastguard Worker call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B) 67*9880d681SAndroid Build Coastguard Worker ret void 68*9880d681SAndroid Build Coastguard Worker} 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker; test conversion of return value... 71*9880d681SAndroid Build Coastguard Workerdefine i8 @test4a() { 72*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test4a( 73*9880d681SAndroid Build Coastguard Worker; CHECK: ret i8 0 74*9880d681SAndroid Build Coastguard Worker ret i8 0 75*9880d681SAndroid Build Coastguard Worker} 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Workerdefine i32 @test4() { 78*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test4( 79*9880d681SAndroid Build Coastguard Worker; CHECK: call i32 bitcast 80*9880d681SAndroid Build Coastguard Worker %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1] 81*9880d681SAndroid Build Coastguard Worker ret i32 %X 82*9880d681SAndroid Build Coastguard Worker} 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Worker; test conversion of return value... no value conversion occurs so we can do 85*9880d681SAndroid Build Coastguard Worker; this with just a prototype... 86*9880d681SAndroid Build Coastguard Workerdeclare i32 @test5a() 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard Workerdefine i32 @test5() { 89*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test5( 90*9880d681SAndroid Build Coastguard Worker; CHECK: %X = call i32 @test5a() 91*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 %X 92*9880d681SAndroid Build Coastguard Worker %X = call i32 @test5a( ) ; <i32> [#uses=1] 93*9880d681SAndroid Build Coastguard Worker ret i32 %X 94*9880d681SAndroid Build Coastguard Worker} 95*9880d681SAndroid Build Coastguard Worker 96*9880d681SAndroid Build Coastguard Worker; test addition of new arguments... 97*9880d681SAndroid Build Coastguard Workerdeclare i32 @test6a(i32) 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Workerdefine i32 @test6() { 100*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test6( 101*9880d681SAndroid Build Coastguard Worker; CHECK: %X = call i32 @test6a(i32 0) 102*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 %X 103*9880d681SAndroid Build Coastguard Worker %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( ) 104*9880d681SAndroid Build Coastguard Worker ret i32 %X 105*9880d681SAndroid Build Coastguard Worker} 106*9880d681SAndroid Build Coastguard Worker 107*9880d681SAndroid Build Coastguard Worker; test removal of arguments, only can happen with a function body 108*9880d681SAndroid Build Coastguard Workerdefine void @test7a() { 109*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test7a( 110*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 111*9880d681SAndroid Build Coastguard Worker ret void 112*9880d681SAndroid Build Coastguard Worker} 113*9880d681SAndroid Build Coastguard Worker 114*9880d681SAndroid Build Coastguard Workerdefine void @test7() { 115*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test7( 116*9880d681SAndroid Build Coastguard Worker; CHECK: call void @test7a() 117*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 118*9880d681SAndroid Build Coastguard Worker call void bitcast (void ()* @test7a to void (i32)*)( i32 5 ) 119*9880d681SAndroid Build Coastguard Worker ret void 120*9880d681SAndroid Build Coastguard Worker} 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Worker; rdar://7590304 124*9880d681SAndroid Build Coastguard Workerdeclare void @test8a() 125*9880d681SAndroid Build Coastguard Worker 126*9880d681SAndroid Build Coastguard Workerdefine i8* @test8() personality i32 (...)* @__gxx_personality_v0 { 127*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test8( 128*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: invoke void @test8a() 129*9880d681SAndroid Build Coastguard Worker; Don't turn this into "unreachable": the callee and caller don't agree in 130*9880d681SAndroid Build Coastguard Worker; calling conv, but the implementation of test8a may actually end up using the 131*9880d681SAndroid Build Coastguard Worker; right calling conv. 132*9880d681SAndroid Build Coastguard Worker invoke void @test8a() 133*9880d681SAndroid Build Coastguard Worker to label %invoke.cont unwind label %try.handler 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Workerinvoke.cont: ; preds = %entry 136*9880d681SAndroid Build Coastguard Worker unreachable 137*9880d681SAndroid Build Coastguard Worker 138*9880d681SAndroid Build Coastguard Workertry.handler: ; preds = %entry 139*9880d681SAndroid Build Coastguard Worker %exn = landingpad {i8*, i32} 140*9880d681SAndroid Build Coastguard Worker cleanup 141*9880d681SAndroid Build Coastguard Worker ret i8* null 142*9880d681SAndroid Build Coastguard Worker} 143*9880d681SAndroid Build Coastguard Worker 144*9880d681SAndroid Build Coastguard Workerdeclare i32 @__gxx_personality_v0(...) 145*9880d681SAndroid Build Coastguard Worker 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard Worker; Don't turn this into a direct call, because test9x is just a prototype and 148*9880d681SAndroid Build Coastguard Worker; doing so will make it varargs. 149*9880d681SAndroid Build Coastguard Worker; rdar://9038601 150*9880d681SAndroid Build Coastguard Workerdeclare i8* @test9x(i8*, i8*, ...) noredzone 151*9880d681SAndroid Build Coastguard Workerdefine i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone { 152*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test9 153*9880d681SAndroid Build Coastguard Workerentry: 154*9880d681SAndroid Build Coastguard Worker %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone 155*9880d681SAndroid Build Coastguard Worker ret i8* %call 156*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test9( 157*9880d681SAndroid Build Coastguard Worker; CHECK: call i8* bitcast 158*9880d681SAndroid Build Coastguard Worker} 159*9880d681SAndroid Build Coastguard Worker 160*9880d681SAndroid Build Coastguard Worker 161*9880d681SAndroid Build Coastguard Worker; Parameter that's a vector of pointers 162*9880d681SAndroid Build Coastguard Workerdeclare void @test10a(<2 x i8*>) 163*9880d681SAndroid Build Coastguard Worker 164*9880d681SAndroid Build Coastguard Workerdefine void @test10(<2 x i32*> %A) { 165*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test10( 166*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast <2 x i32*> %A to <2 x i8*> 167*9880d681SAndroid Build Coastguard Worker; CHECK: call void @test10a(<2 x i8*> %1) 168*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 169*9880d681SAndroid Build Coastguard Worker call void bitcast (void (<2 x i8*>)* @test10a to void (<2 x i32*>)*)(<2 x i32*> %A) 170*9880d681SAndroid Build Coastguard Worker ret void 171*9880d681SAndroid Build Coastguard Worker} 172*9880d681SAndroid Build Coastguard Worker 173*9880d681SAndroid Build Coastguard Worker; Don't transform because different address spaces 174*9880d681SAndroid Build Coastguard Workerdeclare void @test10a_mixed_as(<2 x i8 addrspace(1)*>) 175*9880d681SAndroid Build Coastguard Worker 176*9880d681SAndroid Build Coastguard Workerdefine void @test10_mixed_as(<2 x i8*> %A) { 177*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test10_mixed_as( 178*9880d681SAndroid Build Coastguard Worker; CHECK: call void bitcast 179*9880d681SAndroid Build Coastguard Worker call void bitcast (void (<2 x i8 addrspace(1)*>)* @test10a_mixed_as to void (<2 x i8*>)*)(<2 x i8*> %A) 180*9880d681SAndroid Build Coastguard Worker ret void 181*9880d681SAndroid Build Coastguard Worker} 182*9880d681SAndroid Build Coastguard Worker 183*9880d681SAndroid Build Coastguard Worker; Return type that's a pointer 184*9880d681SAndroid Build Coastguard Workerdefine i8* @test11a() { 185*9880d681SAndroid Build Coastguard Worker ret i8* zeroinitializer 186*9880d681SAndroid Build Coastguard Worker} 187*9880d681SAndroid Build Coastguard Worker 188*9880d681SAndroid Build Coastguard Workerdefine i32* @test11() { 189*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test11( 190*9880d681SAndroid Build Coastguard Worker; CHECK: %X = call i8* @test11a() 191*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast i8* %X to i32* 192*9880d681SAndroid Build Coastguard Worker %X = call i32* bitcast (i8* ()* @test11a to i32* ()*)() 193*9880d681SAndroid Build Coastguard Worker ret i32* %X 194*9880d681SAndroid Build Coastguard Worker} 195*9880d681SAndroid Build Coastguard Worker 196*9880d681SAndroid Build Coastguard Worker; Return type that's a pointer with a different address space 197*9880d681SAndroid Build Coastguard Workerdefine i8 addrspace(1)* @test11a_mixed_as() { 198*9880d681SAndroid Build Coastguard Worker ret i8 addrspace(1)* zeroinitializer 199*9880d681SAndroid Build Coastguard Worker} 200*9880d681SAndroid Build Coastguard Worker 201*9880d681SAndroid Build Coastguard Workerdefine i8* @test11_mixed_as() { 202*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test11_mixed_as( 203*9880d681SAndroid Build Coastguard Worker; CHECK: call i8* bitcast 204*9880d681SAndroid Build Coastguard Worker %X = call i8* bitcast (i8 addrspace(1)* ()* @test11a_mixed_as to i8* ()*)() 205*9880d681SAndroid Build Coastguard Worker ret i8* %X 206*9880d681SAndroid Build Coastguard Worker} 207*9880d681SAndroid Build Coastguard Worker 208*9880d681SAndroid Build Coastguard Worker; Return type that's a vector of pointers 209*9880d681SAndroid Build Coastguard Workerdefine <2 x i8*> @test12a() { 210*9880d681SAndroid Build Coastguard Worker ret <2 x i8*> zeroinitializer 211*9880d681SAndroid Build Coastguard Worker} 212*9880d681SAndroid Build Coastguard Worker 213*9880d681SAndroid Build Coastguard Workerdefine <2 x i32*> @test12() { 214*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test12( 215*9880d681SAndroid Build Coastguard Worker; CHECK: %X = call <2 x i8*> @test12a() 216*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast <2 x i8*> %X to <2 x i32*> 217*9880d681SAndroid Build Coastguard Worker %X = call <2 x i32*> bitcast (<2 x i8*> ()* @test12a to <2 x i32*> ()*)() 218*9880d681SAndroid Build Coastguard Worker ret <2 x i32*> %X 219*9880d681SAndroid Build Coastguard Worker} 220*9880d681SAndroid Build Coastguard Worker 221*9880d681SAndroid Build Coastguard Workerdefine <2 x i8 addrspace(1)*> @test12a_mixed_as() { 222*9880d681SAndroid Build Coastguard Worker ret <2 x i8 addrspace(1)*> zeroinitializer 223*9880d681SAndroid Build Coastguard Worker} 224*9880d681SAndroid Build Coastguard Worker 225*9880d681SAndroid Build Coastguard Workerdefine <2 x i8*> @test12_mixed_as() { 226*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test12_mixed_as( 227*9880d681SAndroid Build Coastguard Worker; CHECK: call <2 x i8*> bitcast 228*9880d681SAndroid Build Coastguard Worker %X = call <2 x i8*> bitcast (<2 x i8 addrspace(1)*> ()* @test12a_mixed_as to <2 x i8*> ()*)() 229*9880d681SAndroid Build Coastguard Worker ret <2 x i8*> %X 230*9880d681SAndroid Build Coastguard Worker} 231*9880d681SAndroid Build Coastguard Worker 232*9880d681SAndroid Build Coastguard Worker 233*9880d681SAndroid Build Coastguard Worker; Mix parameter that's a vector of integers and pointers of the same size 234*9880d681SAndroid Build Coastguard Workerdeclare void @test13a(<2 x i64>) 235*9880d681SAndroid Build Coastguard Worker 236*9880d681SAndroid Build Coastguard Workerdefine void @test13(<2 x i32*> %A) { 237*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test13( 238*9880d681SAndroid Build Coastguard Worker; CHECK: call void bitcast 239*9880d681SAndroid Build Coastguard Worker call void bitcast (void (<2 x i64>)* @test13a to void (<2 x i32*>)*)(<2 x i32*> %A) 240*9880d681SAndroid Build Coastguard Worker ret void 241*9880d681SAndroid Build Coastguard Worker} 242*9880d681SAndroid Build Coastguard Worker 243*9880d681SAndroid Build Coastguard Worker; Mix parameter that's a vector of integers and pointers of the same 244*9880d681SAndroid Build Coastguard Worker; size, but the other way around 245*9880d681SAndroid Build Coastguard Workerdeclare void @test14a(<2 x i8*>) 246*9880d681SAndroid Build Coastguard Worker 247*9880d681SAndroid Build Coastguard Workerdefine void @test14(<2 x i64> %A) { 248*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test14( 249*9880d681SAndroid Build Coastguard Worker; CHECK: call void bitcast 250*9880d681SAndroid Build Coastguard Worker call void bitcast (void (<2 x i8*>)* @test14a to void (<2 x i64>)*)(<2 x i64> %A) 251*9880d681SAndroid Build Coastguard Worker ret void 252*9880d681SAndroid Build Coastguard Worker} 253*9880d681SAndroid Build Coastguard Worker 254*9880d681SAndroid Build Coastguard Worker 255*9880d681SAndroid Build Coastguard Worker; Return type that's a vector 256*9880d681SAndroid Build Coastguard Workerdefine <2 x i16> @test15a() { 257*9880d681SAndroid Build Coastguard Worker ret <2 x i16> zeroinitializer 258*9880d681SAndroid Build Coastguard Worker} 259*9880d681SAndroid Build Coastguard Worker 260*9880d681SAndroid Build Coastguard Workerdefine i32 @test15() { 261*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test15( 262*9880d681SAndroid Build Coastguard Worker; CHECK: %X = call <2 x i16> @test15a() 263*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast <2 x i16> %X to i32 264*9880d681SAndroid Build Coastguard Worker %X = call i32 bitcast (<2 x i16> ()* @test15a to i32 ()*)( ) 265*9880d681SAndroid Build Coastguard Worker ret i32 %X 266*9880d681SAndroid Build Coastguard Worker} 267*9880d681SAndroid Build Coastguard Worker 268*9880d681SAndroid Build Coastguard Workerdefine i32 @test16a() { 269*9880d681SAndroid Build Coastguard Worker ret i32 0 270*9880d681SAndroid Build Coastguard Worker} 271*9880d681SAndroid Build Coastguard Worker 272*9880d681SAndroid Build Coastguard Workerdefine <2 x i16> @test16() { 273*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test16( 274*9880d681SAndroid Build Coastguard Worker; CHECK: %X = call i32 @test16a() 275*9880d681SAndroid Build Coastguard Worker; CHECK: %1 = bitcast i32 %X to <2 x i16> 276*9880d681SAndroid Build Coastguard Worker %X = call <2 x i16> bitcast (i32 ()* @test16a to <2 x i16> ()*)( ) 277*9880d681SAndroid Build Coastguard Worker ret <2 x i16> %X 278*9880d681SAndroid Build Coastguard Worker} 279