1 ; RUN: opt -tbaa -basicaa -gvn -S < %s | FileCheck %s
3 target datalayout = "e-p:64:64:64"
5 ; GVN should ignore the store to p1 to see that the load from p is
6 ; fully redundant.
8 ; CHECK: @yes
9 ; CHECK: if.then:
10 ; CHECK-NEXT: store i32 0, i32* %q
11 ; CHECK-NEXT: ret void
13 define void @yes(i1 %c, i32* %p, i32* %p1, i32* %q) nounwind {
14 entry:
15 store i32 0, i32* %p, !tbaa !1
16 store i32 1, i32* %p1, !tbaa !2
17 br i1 %c, label %if.else, label %if.then
19 if.then:
20 %t = load i32* %p, !tbaa !1
21 store i32 %t, i32* %q
22 ret void
24 if.else:
25 ret void
26 }
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.
33 ; CHECK: @watch_out_for_type_change
34 ; CHECK: if.then:
35 ; CHECK: %t = load i32* %p
36 ; CHECK: store i32 %t, i32* %q
37 ; CHECK: ret void
38 ; CHECK: if.else:
39 ; CHECK: %u = load i32* %p
40 ; CHECK: store i32 %u, i32* %q
42 define void @watch_out_for_type_change(i1 %c, i32* %p, i32* %p1, i32* %q) nounwind {
43 entry:
44 store i32 0, i32* %p, !tbaa !1
45 store i32 1, i32* %p1, !tbaa !2
46 br i1 %c, label %if.else, label %if.then
48 if.then:
49 %t = load i32* %p, !tbaa !4
50 store i32 %t, i32* %q
51 ret void
53 if.else:
54 %u = load i32* %p, !tbaa !3
55 store i32 %u, i32* %q
56 ret void
57 }
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.
62 ; CHECK: @watch_out_for_another_type_change
63 ; CHECK: if.then:
64 ; CHECK: %t = load i32* %p
65 ; CHECK: store i32 %t, i32* %q
66 ; CHECK: ret void
67 ; CHECK: if.else:
68 ; CHECK: store i32 0, i32* %q
70 define void @watch_out_for_another_type_change(i1 %c, i32* %p, i32* %p1, i32* %q) nounwind {
71 entry:
72 store i32 0, i32* %p, !tbaa !1
73 store i32 1, i32* %p1, !tbaa !2
74 br i1 %c, label %if.else, label %if.then
76 if.then:
77 %t = load i32* %p, !tbaa !3
78 store i32 %t, i32* %q
79 ret void
81 if.else:
82 %u = load i32* %p, !tbaa !4
83 store i32 %u, i32* %q
84 ret void
85 }
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"}
95 !8 = !{!"brick red", !5}