1 ; RUN: opt < %s -passes=dse -S | FileCheck %s
3 declare noalias ptr @calloc(i64, i64) inaccessiblememonly allockind("alloc,zeroed")
7 %1 = tail call noalias ptr @calloc(i64 1, i64 4)
8 ; This store is dead and should be removed
9 store i32 0, ptr %1, align 4
10 ; CHECK-NOT: store i32 0, ptr %1, align 4
16 %1 = tail call noalias ptr @calloc(i64 1, i64 4)
17 %2 = getelementptr i32, ptr %1, i32 5
18 store i32 0, ptr %2, align 4
19 ; CHECK-NOT: store i32 0, ptr %1, align 4
23 define ptr @test3(ptr %arg) {
25 store i32 0, ptr %arg, align 4
26 ; CHECK: store i32 0, ptr %arg, align 4
30 declare void @clobber_memory(ptr)
33 %1 = tail call noalias ptr @calloc(i64 1, i64 4)
34 call void @clobber_memory(ptr %1)
35 store i8 0, ptr %1, align 4
36 ; CHECK: store i8 0, ptr %1, align 4
42 %1 = tail call noalias ptr @calloc(i64 1, i64 4)
43 store volatile i32 0, ptr %1, align 4
44 ; CHECK: store volatile i32 0, ptr %1, align 4
50 %1 = tail call noalias ptr @calloc(i64 1, i64 4)
51 store i8 5, ptr %1, align 4
52 ; CHECK: store i8 5, ptr %1, align 4
56 define ptr @test7(i8 %arg) {
58 %1 = tail call noalias ptr @calloc(i64 1, i64 4)
59 store i8 %arg, ptr %1, align 4
60 ; CHECK: store i8 %arg, ptr %1, align 4
67 %p = tail call noalias ptr @calloc(i64 1, i64 4)
68 store i8 0, ptr %p, align 1
69 %p.1 = getelementptr i8, ptr %p, i32 1
70 store i8 0, ptr %p.1, align 1
71 %p.3 = getelementptr i8, ptr %p, i32 3
72 store i8 0, ptr %p.3, align 1
73 %p.2 = getelementptr i8, ptr %p, i32 2
74 store i8 0, ptr %p.2, align 1
80 ; CHECK-NEXT: %p = tail call noalias ptr @calloc(i64 1, i64 4)
81 ; CHECK-NEXT: store i8 5, ptr %p, align 1
82 ; CHECK-NEXT: ret ptr %p
84 %p = tail call noalias ptr @calloc(i64 1, i64 4)
85 store i8 5, ptr %p, align 1
86 %p.1 = getelementptr i8, ptr %p, i32 1
87 store i8 0, ptr %p.1, align 1
88 %p.3 = getelementptr i8, ptr %p, i32 3
89 store i8 0, ptr %p.3, align 1
90 %p.2 = getelementptr i8, ptr %p, i32 2
91 store i8 0, ptr %p.2, align 1
95 define ptr @test10() {
96 ; CHECK-LABEL: @test10(
97 ; CHECK-NEXT: [[P:%.*]] = tail call noalias ptr @calloc(i64 1, i64 4)
98 ; CHECK-NEXT: [[P_3:%.*]] = getelementptr i8, ptr [[P]], i32 3
99 ; CHECK-NEXT: store i8 5, ptr [[P_3]], align 1
100 ; CHECK-NEXT: ret ptr [[P]]
103 %p = tail call noalias ptr @calloc(i64 1, i64 4)
104 store i8 0, ptr %p, align 1
105 %p.1 = getelementptr i8, ptr %p, i32 1
106 store i8 0, ptr %p.1, align 1
107 %p.3 = getelementptr i8, ptr %p, i32 3
108 store i8 5, ptr %p.3, align 1
109 %p.2 = getelementptr i8, ptr %p, i32 2
110 store i8 0, ptr %p.2, align 1
114 define ptr @test11() {
115 ; CHECK-LABEL: @test11(
116 ; CHECK-NEXT: [[P:%.*]] = tail call noalias ptr @calloc(i64 1, i64 4)
117 ; CHECK-NEXT: ret ptr [[P]]
120 %p = tail call noalias ptr @calloc(i64 1, i64 4)
121 store i8 0, ptr %p, align 1
122 %p.1 = getelementptr i8, ptr %p, i32 1
123 store i8 0, ptr %p.1, align 1
124 %p.3 = getelementptr i8, ptr %p, i32 3
125 store i8 5, ptr %p.3, align 1
126 %p.2 = getelementptr i8, ptr %p, i32 2
127 store i8 0, ptr %p.2, align 1
128 %p.3.2 = getelementptr i8, ptr %p, i32 3
129 store i8 0, ptr %p.3.2, align 1
133 define ptr @test12() {
134 ; CHECK-LABEL: @test12(
135 ; CHECK-NEXT: [[P:%.*]] = tail call noalias ptr @calloc(i64 1, i64 4)
136 ; CHECK-NEXT: [[P_3:%.*]] = getelementptr i8, ptr [[P]], i32 3
137 ; CHECK-NEXT: store i8 5, ptr [[P_3]], align 1
138 ; CHECK-NEXT: call void @use(ptr [[P]])
139 ; CHECK-NEXT: [[P_3_2:%.*]] = getelementptr i8, ptr [[P]], i32 3
140 ; CHECK-NEXT: store i8 0, ptr [[P_3_2]], align 1
141 ; CHECK-NEXT: ret ptr [[P]]
144 %p = tail call noalias ptr @calloc(i64 1, i64 4)
145 %p.3 = getelementptr i8, ptr %p, i32 3
146 store i8 5, ptr %p.3, align 1
147 call void @use(ptr %p)
148 %p.3.2 = getelementptr i8, ptr %p, i32 3
149 store i8 0, ptr %p.3.2, align 1
153 declare void @use(ptr) readonly