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
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 {
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
20 %t = load i32* %p, !tbaa !1
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
35 ; CHECK: %t = load i32* %p
36 ; CHECK: store i32 %t, i32* %q
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 {
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
49 %t = load i32* %p, !tbaa !4
54 %u = load i32* %p, !tbaa !3
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
64 ; CHECK: %t = load i32* %p
65 ; CHECK: store i32 %t, i32* %q
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 {
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
77 %t = load i32* %p, !tbaa !3
82 %u = load i32* %p, !tbaa !4
88 !1 = metadata !{metadata !"red", metadata !0}
89 !2 = metadata !{metadata !"blu", metadata !0}
90 !3 = metadata !{metadata !"outer space"}
91 !4 = metadata !{metadata !"brick red", metadata !1}