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