xref: /aosp_15_r20/external/clang/test/CodeGen/byval-memcpy-elim.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s
2*67e74705SXin Li 
3*67e74705SXin Li struct Test1S {
4*67e74705SXin Li  long NumDecls;
5*67e74705SXin Li  long X;
6*67e74705SXin Li  long Y;
7*67e74705SXin Li };
8*67e74705SXin Li struct Test2S {
9*67e74705SXin Li  long NumDecls;
10*67e74705SXin Li  long X;
11*67e74705SXin Li };
12*67e74705SXin Li 
13*67e74705SXin Li // Make sure we don't generate extra memcpy for lvalues
14*67e74705SXin Li void test1a(struct Test1S, struct Test2S);
15*67e74705SXin Li // CHECK-LABEL: define void @test1(
16*67e74705SXin Li // CHECK-NOT: memcpy
17*67e74705SXin Li // CHECK: call void @test1a
test1(struct Test1S * A,struct Test2S * B)18*67e74705SXin Li void test1(struct Test1S *A, struct Test2S *B) {
19*67e74705SXin Li   test1a(*A, *B);
20*67e74705SXin Li }
21*67e74705SXin Li 
22*67e74705SXin Li // The above gets tricker when the byval argument requires higher alignment
23*67e74705SXin Li // than the natural alignment of the type in question.
24*67e74705SXin Li // rdar://9483886
25*67e74705SXin Li 
26*67e74705SXin Li // Make sure we do generate a memcpy when we cannot guarantee alignment.
27*67e74705SXin Li struct Test3S {
28*67e74705SXin Li   int a,b,c,d,e,f,g,h,i,j,k,l;
29*67e74705SXin Li };
30*67e74705SXin Li void test2a(struct Test3S q);
31*67e74705SXin Li // CHECK-LABEL: define void @test2(
32*67e74705SXin Li // CHECK: alloca %struct.Test3S, align 8
33*67e74705SXin Li // CHECK: memcpy
34*67e74705SXin Li // CHECK: call void @test2a
test2(struct Test3S * q)35*67e74705SXin Li void test2(struct Test3S *q) {
36*67e74705SXin Li   test2a(*q);
37*67e74705SXin Li }
38*67e74705SXin Li 
39*67e74705SXin Li // But make sure we don't generate a memcpy when we can guarantee alignment.
40*67e74705SXin Li void fooey(void);
41*67e74705SXin Li // CHECK-LABEL: define void @test3(
42*67e74705SXin Li // CHECK: alloca %struct.Test3S, align 8
43*67e74705SXin Li // CHECK: call void @fooey
44*67e74705SXin Li // CHECK-NOT: memcpy
45*67e74705SXin Li // CHECK: call void @test2a
46*67e74705SXin Li // CHECK-NOT: memcpy
47*67e74705SXin Li // CHECK: call void @test2a
test3(struct Test3S a)48*67e74705SXin Li void test3(struct Test3S a) {
49*67e74705SXin Li   struct Test3S b = a;
50*67e74705SXin Li   fooey();
51*67e74705SXin Li   test2a(a);
52*67e74705SXin Li   test2a(b);
53*67e74705SXin Li }
54