1 ; RUN: opt -tbaa -basicaa -gvn -S < %s | FileCheck %s 2 3 target 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, i32* %q 11 ; CHECK-NEXT: ret void 12 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 18 19 if.then: 20 %t = load i32, i32* %p, !tbaa !1 21 store i32 %t, i32* %q 22 ret void 23 24 if.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, i32* %p 36 ; CHECK: store i32 %t, i32* %q 37 ; CHECK: ret void 38 ; CHECK: if.else: 39 ; CHECK: %u = load i32, i32* %p 40 ; CHECK: store i32 %u, i32* %q 41 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 47 48 if.then: 49 %t = load i32, i32* %p, !tbaa !3 50 store i32 %t, i32* %q 51 ret void 52 53 if.else: 54 %u = load i32, i32* %p, !tbaa !4 55 store i32 %u, i32* %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, i32* %q 65 ; CHECK: ret void 66 ; CHECK: if.else: 67 ; CHECK: %u = load i32, i32* %p 68 ; CHECK: store i32 %u, i32* %q 69 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 75 76 if.then: 77 %t = load i32, i32* %p, !tbaa !4 78 store i32 %t, i32* %q 79 ret void 80 81 if.else: 82 %u = load i32, i32* %p, !tbaa !3 83 store i32 %u, i32* %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