1; RUN: opt -instcombine -S < %s | FileCheck %s
2;
3; Verify that instcombine preserves TBAA tags when converting a memcpy into
4; a scalar load and store.
5
6target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
7
8declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
9
10%A = type { float }
11
12define void @test1(%A* %a1, %A* %a2) {
13entry:
14; CHECK-LABEL: @test1
15; CHECK: %[[LOAD:.*]] = load i32, {{.*}}, !tbaa [[TAG_A:!.*]]
16; CHECK: store i32 %[[LOAD]], {{.*}}, !tbaa [[TAG_A]]
17; CHECK: ret
18  %0 = bitcast %A* %a1 to i8*
19  %1 = bitcast %A* %a2 to i8*
20  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %0, i8* align 4 %1, i64 4, i1 false), !tbaa !4  ; TAG_A
21  ret void
22}
23
24%B = type { i32 (i8*, i32*, double*)** }
25
26define i32 (i8*, i32*, double*)*** @test2() {
27; CHECK-LABEL: @test2
28; CHECK-NOT: memcpy
29; CHECK: ret
30  %tmp = alloca %B, align 8
31  %tmp1 = bitcast %B* %tmp to i8*
32  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %tmp1, i8* align 8 undef, i64 8, i1 false), !tbaa !7  ; TAG_B
33  %tmp2 = getelementptr %B, %B* %tmp, i32 0, i32 0
34  %tmp3 = load i32 (i8*, i32*, double*)**, i32 (i8*, i32*, double*)*** %tmp2
35  ret i32 (i8*, i32*, double*)*** %tmp2
36}
37
38!0 = !{!"root"}
39!1 = !{!0, !"char"}
40!2 = !{!1, !"float"}
41!3 = !{!1, i64 4, !"A", !2, i64 0, i64 4}
42!4 = !{!3, !3, i64 0, i64 4}
43!5 = !{!1, !"pointer"}
44!6 = !{!1, i64 8, !"B", !5, i64 0, i64 8}
45!7 = !{!6, !6, i64 0, i64 8}
46
47; CHECK-DAG: [[ROOT:!.*]] = !{!"root"}
48; CHECK-DAG: [[TYPE_char:!.*]] = !{[[ROOT]], !"char"}
49; CHECK-DAG: [[TYPE_float:!.*]] = !{[[TYPE_char]], !"float"}
50; CHECK-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 4, !"A", [[TYPE_float]], i64 0, i64 4}
51; CHECK-DAG: [[TAG_A]] = !{[[TYPE_A]], [[TYPE_A]], i64 0, i64 4}
52; Note that the memcpy() call in test2() transforms into an
53; undecorated 'store undef', so TAG_B is not present in the output.
54