1 ; RUN: opt -tbaa -basicaa -newgvn -S < %s | FileCheck %s
3 define i32 @test1(i8* %p, i8* %q) {
4 ; CHECK-LABEL: @test1(i8* %p, i8* %q)
5 ; CHECK: call i32 @foo(i8* %p)
7 ; CHECK: %c = add i32 %a, %a
8 %a = call i32 @foo(i8* %p), !tbaa !0
9 %b = call i32 @foo(i8* %p)
14 define i32 @test2(i8* %p, i8* %q) {
15 ; CHECK-LABEL: @test2(i8* %p, i8* %q)
16 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGC:!.*]]
17 ; CHECK: %c = add i32 %a, %a
18 %a = call i32 @foo(i8* %p), !tbaa !0
19 %b = call i32 @foo(i8* %p), !tbaa !0
24 define i32 @test3(i8* %p, i8* %q) {
25 ; CHECK-LABEL: @test3(i8* %p, i8* %q)
26 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGB:!.*]]
27 ; CHECK: %c = add i32 %a, %a
28 %a = call i32 @foo(i8* %p), !tbaa !3
29 %b = call i32 @foo(i8* %p), !tbaa !3
34 define i32 @test4(i8* %p, i8* %q) {
35 ; CHECK-LABEL: @test4(i8* %p, i8* %q)
36 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGA:!.*]]
37 ; CHECK: %c = add i32 %a, %a
38 %a = call i32 @foo(i8* %p), !tbaa !1
39 %b = call i32 @foo(i8* %p), !tbaa !0
44 define i32 @test5(i8* %p, i8* %q) {
45 ; CHECK-LABEL: @test5(i8* %p, i8* %q)
46 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGA]]
47 ; CHECK: %c = add i32 %a, %a
48 %a = call i32 @foo(i8* %p), !tbaa !0
49 %b = call i32 @foo(i8* %p), !tbaa !1
54 define i32 @test6(i8* %p, i8* %q) {
55 ; CHECK-LABEL: @test6(i8* %p, i8* %q)
56 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGA]]
57 ; CHECK: %c = add i32 %a, %a
58 %a = call i32 @foo(i8* %p), !tbaa !0
59 %b = call i32 @foo(i8* %p), !tbaa !3
64 define i32 @test7(i8* %p, i8* %q) {
65 ; CHECK-LABEL: @test7(i8* %p, i8* %q)
66 ; CHECK: call i32 @foo(i8* %p)
68 ; CHECK: %c = add i32 %a, %a
69 %a = call i32 @foo(i8* %p), !tbaa !4
70 %b = call i32 @foo(i8* %p), !tbaa !3
75 define i32 @test8(i32* %p, i32* %q) {
77 ; CHECK-NEXT: store i32 15, i32* %p
78 ; CHECK-NEXT: ret i32 0
79 ; Since we know the location is invariant, we can forward the
80 ; load across the potentially aliasing store.
82 %a = load i32, i32* %q, !tbaa !10
84 %b = load i32, i32* %q, !tbaa !10
89 define i32 @test9(i32* %p, i32* %q) {
91 ; CHECK-NEXT: call void @clobber()
92 ; CHECK-NEXT: ret i32 0
93 ; Since we know the location is invariant, we can forward the
94 ; load across the potentially aliasing store (within the call).
96 %a = load i32, i32* %q, !tbaa !10
98 %b = load i32, i32* %q, !tbaa !10
103 define i32 @test10(i8* %p, i8* %q) {
104 ; If one access encloses the other, then the merged access is the enclosed one
105 ; and not just the common final access type.
106 ; CHECK-LABEL: @test10
107 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAG_X_i:!.*]]
108 ; CHECK: %c = add i32 %a, %a
109 %a = call i32 @foo(i8* %p), !tbaa !15 ; TAG_X_i
110 %b = call i32 @foo(i8* %p), !tbaa !19 ; TAG_Y_x_i
115 declare void @clobber()
116 declare i32 @foo(i8*) readonly
118 ; CHECK-DAG: [[TAGC]] = !{[[TYPEC:!.*]], [[TYPEC]], i64 0}
119 ; CHECK-DAG: [[TYPEC]] = !{!"C", [[TYPEA:!.*]]}
120 ; CHECK-DAG: [[TYPEA]] = !{!"A", !{{.*}}}
121 ; CHECK-DAG: [[TAGB]] = !{[[TYPEB:!.*]], [[TYPEB]], i64 0}
122 ; CHECK-DAG: [[TYPEB]] = !{!"B", [[TYPEA]]}
123 ; CHECK-DAG: [[TAGA]] = !{[[TYPEA]], [[TYPEA]], i64 0}
124 !0 = !{!5, !5, i64 0}
125 !1 = !{!6, !6, i64 0}
127 !3 = !{!7, !7, i64 0}
128 !4 = !{!11, !11, i64 0}
132 !8 = !{!"another root"}
133 !11 = !{!"scalar type", !8}
135 ; CHECK-DAG: [[TAG_X_i]] = !{[[TYPE_X:!.*]], [[TYPE_int:!.*]], i64 0}
136 ; CHECK-DAG: [[TYPE_X:!.*]] = !{!"struct X", [[TYPE_int]], i64 0}
137 ; CHECK-DAG: [[TYPE_int]] = !{!"int", {{!.*}}, i64 0}
138 !15 = !{!16, !17, i64 0} ; TAG_X_i
139 !16 = !{!"struct X", !17, i64 0} ; struct X { int i; };
140 !17 = !{!"int", !18, i64 0}
141 !18 = !{!"char", !2, i64 0}
143 !19 = !{!20, !17, i64 0} ; TAG_Y_x_i
144 !20 = !{!"struct Y", !16, i64 0} ; struct Y { struct X x; };
146 ; A TBAA structure who's only point is to have a constant location.
147 !9 = !{!"yet another root"}
148 !10 = !{!"node", !9, i64 1}