1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -inline -S | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; Inlining a byval struct should cause an explicit copy into an alloca. 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker %struct.ss = type { i32, i64 } 6*9880d681SAndroid Build Coastguard Worker@.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1] 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Workerdefine internal void @f(%struct.ss* byval %b) nounwind { 9*9880d681SAndroid Build Coastguard Workerentry: 10*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2] 11*9880d681SAndroid Build Coastguard Worker %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1] 12*9880d681SAndroid Build Coastguard Worker %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1] 13*9880d681SAndroid Build Coastguard Worker store i32 %tmp2, i32* %tmp, align 4 14*9880d681SAndroid Build Coastguard Worker ret void 15*9880d681SAndroid Build Coastguard Worker} 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Workerdeclare i32 @printf(i8*, ...) nounwind 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Workerdefine i32 @test1() nounwind { 20*9880d681SAndroid Build Coastguard Workerentry: 21*9880d681SAndroid Build Coastguard Worker %S = alloca %struct.ss ; <%struct.ss*> [#uses=4] 22*9880d681SAndroid Build Coastguard Worker %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1] 23*9880d681SAndroid Build Coastguard Worker store i32 1, i32* %tmp1, align 8 24*9880d681SAndroid Build Coastguard Worker %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1] 25*9880d681SAndroid Build Coastguard Worker store i64 2, i64* %tmp4, align 4 26*9880d681SAndroid Build Coastguard Worker call void @f( %struct.ss* byval %S ) nounwind 27*9880d681SAndroid Build Coastguard Worker ret i32 0 28*9880d681SAndroid Build Coastguard Worker; CHECK: @test1() 29*9880d681SAndroid Build Coastguard Worker; CHECK: %S1 = alloca %struct.ss 30*9880d681SAndroid Build Coastguard Worker; CHECK: %S = alloca %struct.ss 31*9880d681SAndroid Build Coastguard Worker; CHECK: call void @llvm.memcpy 32*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0 33*9880d681SAndroid Build Coastguard Worker} 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker; Inlining a byval struct should NOT cause an explicit copy 36*9880d681SAndroid Build Coastguard Worker; into an alloca if the function is readonly 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Workerdefine internal i32 @f2(%struct.ss* byval %b) nounwind readonly { 39*9880d681SAndroid Build Coastguard Workerentry: 40*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2] 41*9880d681SAndroid Build Coastguard Worker %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1] 42*9880d681SAndroid Build Coastguard Worker %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1] 43*9880d681SAndroid Build Coastguard Worker ret i32 %tmp2 44*9880d681SAndroid Build Coastguard Worker} 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Workerdefine i32 @test2() nounwind { 47*9880d681SAndroid Build Coastguard Workerentry: 48*9880d681SAndroid Build Coastguard Worker %S = alloca %struct.ss ; <%struct.ss*> [#uses=4] 49*9880d681SAndroid Build Coastguard Worker %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1] 50*9880d681SAndroid Build Coastguard Worker store i32 1, i32* %tmp1, align 8 51*9880d681SAndroid Build Coastguard Worker %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1] 52*9880d681SAndroid Build Coastguard Worker store i64 2, i64* %tmp4, align 4 53*9880d681SAndroid Build Coastguard Worker %X = call i32 @f2( %struct.ss* byval %S ) nounwind 54*9880d681SAndroid Build Coastguard Worker ret i32 %X 55*9880d681SAndroid Build Coastguard Worker; CHECK: @test2() 56*9880d681SAndroid Build Coastguard Worker; CHECK: %S = alloca %struct.ss 57*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @llvm.memcpy 58*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 59*9880d681SAndroid Build Coastguard Worker} 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker 62*9880d681SAndroid Build Coastguard Worker; Inlining a byval with an explicit alignment needs to use *at least* that 63*9880d681SAndroid Build Coastguard Worker; alignment on the generated alloca. 64*9880d681SAndroid Build Coastguard Worker; PR8769 65*9880d681SAndroid Build Coastguard Workerdeclare void @g3(%struct.ss* %p) 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Workerdefine internal void @f3(%struct.ss* byval align 64 %b) nounwind { 68*9880d681SAndroid Build Coastguard Worker call void @g3(%struct.ss* %b) ;; Could make alignment assumptions! 69*9880d681SAndroid Build Coastguard Worker ret void 70*9880d681SAndroid Build Coastguard Worker} 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Workerdefine void @test3() nounwind { 73*9880d681SAndroid Build Coastguard Workerentry: 74*9880d681SAndroid Build Coastguard Worker %S = alloca %struct.ss, align 1 ;; May not be aligned. 75*9880d681SAndroid Build Coastguard Worker call void @f3( %struct.ss* byval align 64 %S) nounwind 76*9880d681SAndroid Build Coastguard Worker ret void 77*9880d681SAndroid Build Coastguard Worker; CHECK: @test3() 78*9880d681SAndroid Build Coastguard Worker; CHECK: %S1 = alloca %struct.ss, align 64 79*9880d681SAndroid Build Coastguard Worker; CHECK: %S = alloca %struct.ss 80*9880d681SAndroid Build Coastguard Worker; CHECK: call void @llvm.memcpy 81*9880d681SAndroid Build Coastguard Worker; CHECK: call void @g3(%struct.ss* %S1) 82*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 83*9880d681SAndroid Build Coastguard Worker} 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker; Inlining a byval struct should NOT cause an explicit copy 87*9880d681SAndroid Build Coastguard Worker; into an alloca if the function is readonly, but should increase an alloca's 88*9880d681SAndroid Build Coastguard Worker; alignment to satisfy an explicit alignment request. 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Workerdefine internal i32 @f4(%struct.ss* byval align 64 %b) nounwind readonly { 91*9880d681SAndroid Build Coastguard Worker call void @g3(%struct.ss* %b) 92*9880d681SAndroid Build Coastguard Worker ret i32 4 93*9880d681SAndroid Build Coastguard Worker} 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Workerdefine i32 @test4() nounwind { 96*9880d681SAndroid Build Coastguard Workerentry: 97*9880d681SAndroid Build Coastguard Worker %S = alloca %struct.ss, align 2 ; <%struct.ss*> [#uses=4] 98*9880d681SAndroid Build Coastguard Worker %X = call i32 @f4( %struct.ss* byval align 64 %S ) nounwind 99*9880d681SAndroid Build Coastguard Worker ret i32 %X 100*9880d681SAndroid Build Coastguard Worker; CHECK: @test4() 101*9880d681SAndroid Build Coastguard Worker; CHECK: %S = alloca %struct.ss, align 64 102*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @llvm.memcpy 103*9880d681SAndroid Build Coastguard Worker; CHECK: call void @g3 104*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 4 105*9880d681SAndroid Build Coastguard Worker} 106*9880d681SAndroid Build Coastguard Worker 107*9880d681SAndroid Build Coastguard Worker%struct.S0 = type { i32 } 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker@b = global %struct.S0 { i32 1 }, align 4 110*9880d681SAndroid Build Coastguard Worker@a = common global i32 0, align 4 111*9880d681SAndroid Build Coastguard Worker 112*9880d681SAndroid Build Coastguard Workerdefine internal void @f5(%struct.S0* byval nocapture readonly align 4 %p) { 113*9880d681SAndroid Build Coastguard Workerentry: 114*9880d681SAndroid Build Coastguard Worker store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4 115*9880d681SAndroid Build Coastguard Worker %f2 = getelementptr inbounds %struct.S0, %struct.S0* %p, i64 0, i32 0 116*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %f2, align 4 117*9880d681SAndroid Build Coastguard Worker store i32 %0, i32* @a, align 4 118*9880d681SAndroid Build Coastguard Worker ret void 119*9880d681SAndroid Build Coastguard Worker} 120*9880d681SAndroid Build Coastguard Worker 121*9880d681SAndroid Build Coastguard Workerdefine i32 @test5() { 122*9880d681SAndroid Build Coastguard Workerentry: 123*9880d681SAndroid Build Coastguard Worker tail call void @f5(%struct.S0* byval align 4 @b) 124*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* @a, align 4 125*9880d681SAndroid Build Coastguard Worker ret i32 %0 126*9880d681SAndroid Build Coastguard Worker; CHECK: @test5() 127*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4 128*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load i32, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4 129*9880d681SAndroid Build Coastguard Worker} 130