1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=newgvn -S < %s | FileCheck %s
4 %struct.t = type { ptr }
6 ; The loaded address and the location of the address itself are not aliased,
7 ; so the second reload is not necessary. Check that it can be eliminated.
8 define void @test1(ptr nocapture readonly %p, i32 %v) #0 {
9 ; CHECK-LABEL: define void @test1(
10 ; CHECK-SAME: ptr nocapture readonly [[P:%.*]], i32 [[V:%.*]]) #[[ATTR0:[0-9]+]] {
12 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 4, !tbaa [[TBAA0:![0-9]+]]
13 ; CHECK-NEXT: store volatile i32 [[V]], ptr [[TMP0]], align 4, !tbaa [[TBAA5:![0-9]+]]
14 ; CHECK-NEXT: store volatile i32 [[V]], ptr [[TMP0]], align 4, !tbaa [[TBAA5]]
15 ; CHECK-NEXT: ret void
18 %0 = load ptr, ptr %p, align 4, !tbaa !1
19 store volatile i32 %v, ptr %0, align 4, !tbaa !6
20 %1 = load ptr, ptr %p, align 4, !tbaa !1
21 store volatile i32 %v, ptr %1, align 4, !tbaa !6
25 ; The store via the loaded address may overwrite the address itself.
26 ; Make sure that both loads remain.
27 define void @test2(ptr nocapture readonly %p, i32 %v) #0 {
28 ; CHECK-LABEL: define void @test2(
29 ; CHECK-SAME: ptr nocapture readonly [[P:%.*]], i32 [[V:%.*]]) #[[ATTR0]] {
31 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 4, !tbaa [[TBAA0]]
32 ; CHECK-NEXT: store volatile i32 [[V]], ptr [[TMP0]], align 4, !tbaa [[TBAA0]]
33 ; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[P]], align 4, !tbaa [[TBAA0]]
34 ; CHECK-NEXT: store volatile i32 [[V]], ptr [[TMP1]], align 4, !tbaa [[TBAA0]]
35 ; CHECK-NEXT: ret void
38 %0 = load ptr, ptr %p, align 4, !tbaa !1
39 store volatile i32 %v, ptr %0, align 4, !tbaa !1
40 %1 = load ptr, ptr %p, align 4, !tbaa !1
41 store volatile i32 %v, ptr %1, align 4, !tbaa !1
45 ; The loads are ordered and non-monotonic. Although they are not aliased to
46 ; the stores, make sure both are preserved.
47 define void @test3(ptr nocapture readonly %p, i32 %v) #0 {
48 ; CHECK-LABEL: define void @test3(
49 ; CHECK-SAME: ptr nocapture readonly [[P:%.*]], i32 [[V:%.*]]) #[[ATTR0]] {
51 ; CHECK-NEXT: [[TMP0:%.*]] = load atomic ptr, ptr [[P]] acquire, align 4, !tbaa [[TBAA0]]
52 ; CHECK-NEXT: store volatile i32 [[V]], ptr [[TMP0]], align 4, !tbaa [[TBAA5]]
53 ; CHECK-NEXT: [[TMP1:%.*]] = load atomic ptr, ptr [[P]] acquire, align 4, !tbaa [[TBAA0]]
54 ; CHECK-NEXT: store volatile i32 [[V]], ptr [[TMP1]], align 4, !tbaa [[TBAA5]]
55 ; CHECK-NEXT: ret void
58 %0 = load atomic ptr, ptr %p acquire, align 4, !tbaa !1
59 store volatile i32 %v, ptr %0, align 4, !tbaa !6
60 %1 = load atomic ptr, ptr %p acquire, align 4, !tbaa !1
61 store volatile i32 %v, ptr %1, align 4, !tbaa !6
65 attributes #0 = { norecurse nounwind }
68 !2 = !{!"", !3, i64 0}
69 !3 = !{!"any pointer", !4, i64 0}
70 !4 = !{!"omnipotent char", !5, i64 0}
71 !5 = !{!"Simple C/C++ TBAA"}
73 !7 = !{!"int", !4, i64 0}
76 ; CHECK: [[TBAA0]] = !{[[META1:![0-9]+]], [[META2:![0-9]+]], i64 0}
77 ; CHECK: [[META1]] = !{!"", [[META2]], i64 0}
78 ; CHECK: [[META2]] = !{!"any pointer", [[META3:![0-9]+]], i64 0}
79 ; CHECK: [[META3]] = !{!"omnipotent char", [[META4:![0-9]+]], i64 0}
80 ; CHECK: [[META4]] = !{!"Simple C/C++ TBAA"}
81 ; CHECK: [[TBAA5]] = !{[[META6:![0-9]+]], [[META6]], i64 0}
82 ; CHECK: [[META6]] = !{!"int", [[META3]], i64 0}