1 ; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
3 declare noalias i8* @calloc(i64, i64)
7 %1 = tail call noalias i8* @calloc(i64 1, i64 4)
8 %2 = bitcast i8* %1 to i32*
9 ; This store is dead and should be removed
10 store i32 0, i32* %2, align 4
11 ; CHECK-NOT: store i32 0, i32* %2, align 4
15 define i32* @test2() {
17 %1 = tail call noalias i8* @calloc(i64 1, i64 4)
18 %2 = bitcast i8* %1 to i32*
19 %3 = getelementptr i32, i32* %2, i32 5
20 store i32 0, i32* %3, align 4
21 ; CHECK-NOT: store i32 0, i32* %2, align 4
25 define i32* @test3(i32 *%arg) {
27 store i32 0, i32* %arg, align 4
28 ; CHECK: store i32 0, i32* %arg, align 4
32 declare void @clobber_memory(i8*)
35 %1 = tail call noalias i8* @calloc(i64 1, i64 4)
36 call void @clobber_memory(i8* %1)
37 store i8 0, i8* %1, align 4
38 ; CHECK: store i8 0, i8* %1, align 4
42 define i32* @test5() {
44 %1 = tail call noalias i8* @calloc(i64 1, i64 4)
45 %2 = bitcast i8* %1 to i32*
46 store volatile i32 0, i32* %2, align 4
47 ; CHECK: store volatile i32 0, i32* %2, align 4
53 %1 = tail call noalias i8* @calloc(i64 1, i64 4)
54 store i8 5, i8* %1, align 4
55 ; CHECK: store i8 5, i8* %1, align 4
59 define i8* @test7(i8 %arg) {
61 %1 = tail call noalias i8* @calloc(i64 1, i64 4)
62 store i8 %arg, i8* %1, align 4
63 ; CHECK: store i8 %arg, i8* %1, align 4
70 %p = tail call noalias i8* @calloc(i64 1, i64 4)
71 store i8 0, i8* %p, align 1
72 %p.1 = getelementptr i8, i8* %p, i32 1
73 store i8 0, i8* %p.1, align 1
74 %p.3 = getelementptr i8, i8* %p, i32 3
75 store i8 0, i8* %p.3, align 1
76 %p.2 = getelementptr i8, i8* %p, i32 2
77 store i8 0, i8* %p.2, align 1
83 ; CHECK-NEXT: %p = tail call noalias i8* @calloc(i64 1, i64 4)
84 ; CHECK-NEXT: store i8 5, i8* %p, align 1
85 ; CHECK-NEXT: ret i8* %p
87 %p = tail call noalias i8* @calloc(i64 1, i64 4)
88 store i8 5, i8* %p, align 1
89 %p.1 = getelementptr i8, i8* %p, i32 1
90 store i8 0, i8* %p.1, align 1
91 %p.3 = getelementptr i8, i8* %p, i32 3
92 store i8 0, i8* %p.3, align 1
93 %p.2 = getelementptr i8, i8* %p, i32 2
94 store i8 0, i8* %p.2, align 1
98 define i8* @test10() {
99 ; CHECK-LABEL: @test10(
100 ; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
101 ; CHECK-NEXT: [[P_3:%.*]] = getelementptr i8, i8* [[P]], i32 3
102 ; CHECK-NEXT: store i8 5, i8* [[P_3]], align 1
103 ; CHECK-NEXT: ret i8* [[P]]
106 %p = tail call noalias i8* @calloc(i64 1, i64 4)
107 store i8 0, i8* %p, align 1
108 %p.1 = getelementptr i8, i8* %p, i32 1
109 store i8 0, i8* %p.1, align 1
110 %p.3 = getelementptr i8, i8* %p, i32 3
111 store i8 5, i8* %p.3, align 1
112 %p.2 = getelementptr i8, i8* %p, i32 2
113 store i8 0, i8* %p.2, align 1
117 define i8* @test11() {
118 ; CHECK-LABEL: @test11(
119 ; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
120 ; CHECK-NEXT: ret i8* [[P]]
123 %p = tail call noalias i8* @calloc(i64 1, i64 4)
124 store i8 0, i8* %p, align 1
125 %p.1 = getelementptr i8, i8* %p, i32 1
126 store i8 0, i8* %p.1, align 1
127 %p.3 = getelementptr i8, i8* %p, i32 3
128 store i8 5, i8* %p.3, align 1
129 %p.2 = getelementptr i8, i8* %p, i32 2
130 store i8 0, i8* %p.2, align 1
131 %p.3.2 = getelementptr i8, i8* %p, i32 3
132 store i8 0, i8* %p.3.2, align 1
136 define i8* @test12() {
137 ; CHECK-LABEL: @test12(
138 ; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
139 ; CHECK-NEXT: [[P_3:%.*]] = getelementptr i8, i8* [[P]], i32 3
140 ; CHECK-NEXT: store i8 5, i8* [[P_3]], align 1
141 ; CHECK-NEXT: call void @use(i8* [[P]])
142 ; CHECK-NEXT: [[P_3_2:%.*]] = getelementptr i8, i8* [[P]], i32 3
143 ; CHECK-NEXT: store i8 0, i8* [[P_3_2]], align 1
144 ; CHECK-NEXT: ret i8* [[P]]
147 %p = tail call noalias i8* @calloc(i64 1, i64 4)
148 %p.3 = getelementptr i8, i8* %p, i32 3
149 store i8 5, i8* %p.3, align 1
150 call void @use(i8* %p)
151 %p.3.2 = getelementptr i8, i8* %p, i32 3
152 store i8 0, i8* %p.3.2, align 1
156 declare void @use(i8*) readonly