calloc-store.ll
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
; RUN: opt < %s -basic-aa -dse -enable-dse-memoryssa -S | FileCheck %s
declare noalias i8* @calloc(i64, i64)
define i32* @test1() {
; CHECK-LABEL: test1
%1 = tail call noalias i8* @calloc(i64 1, i64 4)
%2 = bitcast i8* %1 to i32*
; This store is dead and should be removed
store i32 0, i32* %2, align 4
; CHECK-NOT: store i32 0, i32* %2, align 4
ret i32* %2
}
define i32* @test2() {
; CHECK-LABEL: test2
%1 = tail call noalias i8* @calloc(i64 1, i64 4)
%2 = bitcast i8* %1 to i32*
%3 = getelementptr i32, i32* %2, i32 5
store i32 0, i32* %3, align 4
; CHECK-NOT: store i32 0, i32* %2, align 4
ret i32* %2
}
define i32* @test3(i32 *%arg) {
; CHECK-LABEL: test3
store i32 0, i32* %arg, align 4
; CHECK: store i32 0, i32* %arg, align 4
ret i32* %arg
}
declare void @clobber_memory(i8*)
define i8* @test4() {
; CHECK-LABEL: test4
%1 = tail call noalias i8* @calloc(i64 1, i64 4)
call void @clobber_memory(i8* %1)
store i8 0, i8* %1, align 4
; CHECK: store i8 0, i8* %1, align 4
ret i8* %1
}
define i32* @test5() {
; CHECK-LABEL: test5
%1 = tail call noalias i8* @calloc(i64 1, i64 4)
%2 = bitcast i8* %1 to i32*
store volatile i32 0, i32* %2, align 4
; CHECK: store volatile i32 0, i32* %2, align 4
ret i32* %2
}
define i8* @test6() {
; CHECK-LABEL: test6
%1 = tail call noalias i8* @calloc(i64 1, i64 4)
store i8 5, i8* %1, align 4
; CHECK: store i8 5, i8* %1, align 4
ret i8* %1
}
define i8* @test7(i8 %arg) {
; CHECK-LABEL: test7
%1 = tail call noalias i8* @calloc(i64 1, i64 4)
store i8 %arg, i8* %1, align 4
; CHECK: store i8 %arg, i8* %1, align 4
ret i8* %1
}
define i8* @test8() {
; CHECK-LABEL: test8
; CHECK-NOT: store
%p = tail call noalias i8* @calloc(i64 1, i64 4)
store i8 0, i8* %p, align 1
%p.1 = getelementptr i8, i8* %p, i32 1
store i8 0, i8* %p.1, align 1
%p.3 = getelementptr i8, i8* %p, i32 3
store i8 0, i8* %p.3, align 1
%p.2 = getelementptr i8, i8* %p, i32 2
store i8 0, i8* %p.2, align 1
ret i8* %p
}
define i8* @test9() {
; CHECK-LABEL: test9
; CHECK-NEXT: %p = tail call noalias i8* @calloc(i64 1, i64 4)
; CHECK-NEXT: store i8 5, i8* %p, align 1
; CHECK-NEXT: ret i8* %p
%p = tail call noalias i8* @calloc(i64 1, i64 4)
store i8 5, i8* %p, align 1
%p.1 = getelementptr i8, i8* %p, i32 1
store i8 0, i8* %p.1, align 1
%p.3 = getelementptr i8, i8* %p, i32 3
store i8 0, i8* %p.3, align 1
%p.2 = getelementptr i8, i8* %p, i32 2
store i8 0, i8* %p.2, align 1
ret i8* %p
}
define i8* @test10() {
; CHECK-LABEL: @test10(
; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
; CHECK-NEXT: [[P_3:%.*]] = getelementptr i8, i8* [[P]], i32 3
; CHECK-NEXT: store i8 5, i8* [[P_3]], align 1
; CHECK-NEXT: ret i8* [[P]]
;
%p = tail call noalias i8* @calloc(i64 1, i64 4)
store i8 0, i8* %p, align 1
%p.1 = getelementptr i8, i8* %p, i32 1
store i8 0, i8* %p.1, align 1
%p.3 = getelementptr i8, i8* %p, i32 3
store i8 5, i8* %p.3, align 1
%p.2 = getelementptr i8, i8* %p, i32 2
store i8 0, i8* %p.2, align 1
ret i8* %p
}
; TODO: we could also eliminate the last store i8 0, i8* %p.3.2, but currently
; don't because those are eliminated before eliminating killed stores.
define i8* @test11() {
; CHECK-LABEL: @test11(
; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
; CHECK-NEXT: [[P_3_2:%.*]] = getelementptr i8, i8* [[P]], i32 3
; CHECK-NEXT: store i8 0, i8* [[P_3_2]], align 1
; CHECK-NEXT: ret i8* [[P]]
;
%p = tail call noalias i8* @calloc(i64 1, i64 4)
store i8 0, i8* %p, align 1
%p.1 = getelementptr i8, i8* %p, i32 1
store i8 0, i8* %p.1, align 1
%p.3 = getelementptr i8, i8* %p, i32 3
store i8 5, i8* %p.3, align 1
%p.2 = getelementptr i8, i8* %p, i32 2
store i8 0, i8* %p.2, align 1
%p.3.2 = getelementptr i8, i8* %p, i32 3
store i8 0, i8* %p.3.2, align 1
ret i8* %p
}
define i8* @test12() {
; CHECK-LABEL: @test12(
; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
; CHECK-NEXT: [[P_3:%.*]] = getelementptr i8, i8* [[P]], i32 3
; CHECK-NEXT: store i8 5, i8* [[P_3]], align 1
; CHECK-NEXT: call void @use(i8* [[P]])
; CHECK-NEXT: [[P_3_2:%.*]] = getelementptr i8, i8* [[P]], i32 3
; CHECK-NEXT: store i8 0, i8* [[P_3_2]], align 1
; CHECK-NEXT: ret i8* [[P]]
;
%p = tail call noalias i8* @calloc(i64 1, i64 4)
%p.3 = getelementptr i8, i8* %p, i32 3
store i8 5, i8* %p.3, align 1
call void @use(i8* %p)
%p.3.2 = getelementptr i8, i8* %p, i32 3
store i8 0, i8* %p.3.2, align 1
ret i8* %p
}
declare void @use(i8*) readonly