1; RUN: opt < %s -argpromotion -S | FileCheck %s
2; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
3
4; PR17906
5; When we promote two arguments in a single function with different types,
6; before the fix, we used the same tag for the newly-created two loads.
7; This testing case makes sure that we correctly transfer the tbaa tags from the
8; original loads to the newly-created loads when promoting pointer arguments.
9
10@a = global i32* null, align 8
11@e = global i32** @a, align 8
12@g = global i32 0, align 4
13@c = global i64 0, align 8
14@d = global i8 0, align 1
15
16define internal fastcc void @fn(i32* nocapture readonly %p1, i64* nocapture readonly %p2) {
17entry:
18  %0 = load i64, i64* %p2, align 8, !tbaa !1
19  %conv = trunc i64 %0 to i32
20  %1 = load i32, i32* %p1, align 4, !tbaa !5
21  %conv1 = trunc i32 %1 to i8
22  store i8 %conv1, i8* @d, align 1, !tbaa !7
23  ret void
24}
25
26define i32 @main() {
27entry:
28; CHECK-LABEL: main
29; CHECK: store i32 1, i32* %{{.*}}, align 4, !tbaa ![[I32:[0-9]+]]
30; CHECK: %g.val = load i32, i32* @g, align 4, !tbaa ![[I32]]
31; CHECK: %c.val = load i64, i64* @c, align 8, !tbaa ![[LONG:[0-9]+]]
32  %0 = load i32**, i32*** @e, align 8, !tbaa !8
33  store i32* @g, i32** %0, align 8, !tbaa !8
34  %1 = load i32*, i32** @a, align 8, !tbaa !8
35  store i32 1, i32* %1, align 4, !tbaa !5
36  call fastcc void @fn(i32* @g, i64* @c)
37
38  ret i32 0
39}
40
41!1 = !{!2, !2, i64 0}
42!2 = !{!"long", !3, i64 0}
43!3 = !{!"omnipotent char", !4, i64 0}
44!4 = !{!"Simple C/C++ TBAA"}
45!5 = !{!6, !6, i64 0}
46!6 = !{!"int", !3, i64 0}
47!7 = !{!3, !3, i64 0}
48!8 = !{!9, !9, i64 0}
49!9 = !{!"any pointer", !3, i64 0}
50; CHECK: ![[I32]] = !{![[I32_TYPE:[0-9]+]], ![[I32_TYPE]], i64 0}
51; CHECK: ![[I32_TYPE]] = !{!"int", !{{.*}}, i64 0}
52; CHECK: ![[LONG]] = !{![[LONG_TYPE:[0-9]+]], ![[LONG_TYPE]], i64 0}
53; CHECK: ![[LONG_TYPE]] = !{!"long", !{{.*}}, i64 0}
54