xref: /llvm-project/llvm/test/Analysis/TypeBasedAliasAnalysis/gvn-nonlocal-type-mismatch.ll (revision 6402fc22e1bccd0984beadfe931511175bac688c)
1; RUN: opt -aa-pipeline=tbaa,basic-aa -passes=gvn -S < %s | FileCheck %s
2
3target datalayout = "e-p:64:64:64"
4
5; GVN should ignore the store to p1 to see that the load from p is
6; fully redundant.
7
8; CHECK: @yes
9; CHECK: if.then:
10; CHECK-NEXT: store i32 0, ptr %q
11; CHECK-NEXT: ret void
12
13define void @yes(i1 %c, ptr %p, ptr %p1, ptr %q) nounwind {
14entry:
15  store i32 0, ptr %p, !tbaa !1
16  store i32 1, ptr %p1, !tbaa !2
17  br i1 %c, label %if.else, label %if.then
18
19if.then:
20  %t = load i32, ptr %p, !tbaa !1
21  store i32 %t, ptr %q
22  ret void
23
24if.else:
25  ret void
26}
27
28; GVN should ignore the store to p1 to see that the first load from p is
29; fully redundant. However, the second load uses a different type. Theoretically
30; the other type could be unified with the first type, however for now, GVN
31; should just be conservative.
32
33; CHECK: @watch_out_for_type_change
34; CHECK: if.then:
35; CHECK:   %t = load i32, ptr %p
36; CHECK:   store i32 %t, ptr %q
37; CHECK:   ret void
38; CHECK: if.else:
39; CHECK:   %u = load i32, ptr %p
40; CHECK:   store i32 %u, ptr %q
41
42define void @watch_out_for_type_change(i1 %c, ptr %p, ptr %p1, ptr %q) nounwind {
43entry:
44  store i32 0, ptr %p, !tbaa !1
45  store i32 1, ptr %p1, !tbaa !2
46  br i1 %c, label %if.else, label %if.then
47
48if.then:
49  %t = load i32, ptr %p, !tbaa !3
50  store i32 %t, ptr %q
51  ret void
52
53if.else:
54  %u = load i32, ptr %p, !tbaa !4
55  store i32 %u, ptr %q
56  ret void
57}
58
59; As before, but the types are swapped. This time GVN does managed to
60; eliminate one of the loads before noticing the type mismatch.
61
62; CHECK: @watch_out_for_another_type_change
63; CHECK: if.then:
64; CHECK:   store i32 0, ptr %q
65; CHECK:   ret void
66; CHECK: if.else:
67; CHECK:   %u = load i32, ptr %p
68; CHECK:   store i32 %u, ptr %q
69
70define void @watch_out_for_another_type_change(i1 %c, ptr %p, ptr %p1, ptr %q) nounwind {
71entry:
72  store i32 0, ptr %p, !tbaa !1
73  store i32 1, ptr %p1, !tbaa !2
74  br i1 %c, label %if.else, label %if.then
75
76if.then:
77  %t = load i32, ptr %p, !tbaa !4
78  store i32 %t, ptr %q
79  ret void
80
81if.else:
82  %u = load i32, ptr %p, !tbaa !3
83  store i32 %u, ptr %q
84  ret void
85}
86
87!0 = !{}
88!1 = !{!5, !5, i64 0}
89!2 = !{!6, !6, i64 0}
90!3 = !{!7, !7, i64 0}
91!4 = !{!8, !8, i64 0}
92!5 = !{!"red", !0}
93!6 = !{!"blu", !0}
94!7 = !{!"outer space", !9}
95!8 = !{!"brick red", !5}
96!9 = !{!"observable universe"}
97