0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 define void @test1(i32* %P) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 store i32 undef, i32* %P
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 store i32 123, i32* undef
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 store i32 124, i32* null
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 ; CHECK-LABEL: @test1(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 ; CHECK-NEXT: store i32 123, i32* undef
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 ; CHECK-NEXT: store i32 undef, i32* null
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 ; CHECK-NEXT: ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 define void @test2(i32* %P) {
|
95
|
15 %X = load i32, i32* %P ; <i32> [#uses=1]
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 %Y = add i32 %X, 0 ; <i32> [#uses=1]
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 store i32 %Y, i32* %P
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 ; CHECK-LABEL: @test2(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 ; CHECK-NEXT: ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22
|
134
|
23 define void @store_at_gep_off_null(i64 %offset) {
|
|
24 ; CHECK-LABEL: @store_at_gep_off_null
|
|
25 ; CHECK: store i32 undef, i32* %ptr
|
|
26 %ptr = getelementptr i32, i32 *null, i64 %offset
|
|
27 store i32 24, i32* %ptr
|
|
28 ret void
|
|
29 }
|
|
30
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 ;; Simple sinking tests
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 ; "if then else"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 define i32 @test3(i1 %C) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 %A = alloca i32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 br i1 %C, label %Cond, label %Cond2
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 Cond:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 store i32 -987654321, i32* %A
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 br label %Cont
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 Cond2:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 store i32 47, i32* %A
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 br label %Cont
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 Cont:
|
95
|
47 %V = load i32, i32* %A
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 ret i32 %V
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 ; CHECK-LABEL: @test3(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 ; CHECK-NOT: alloca
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 ; CHECK: Cont:
|
95
|
52 ; CHECK-NEXT: %storemerge = phi i32 [ -987654321, %Cond ], [ 47, %Cond2 ]
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 ; CHECK-NEXT: ret i32 %storemerge
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 ; "if then"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 define i32 @test4(i1 %C) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 %A = alloca i32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 store i32 47, i32* %A
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 br i1 %C, label %Cond, label %Cont
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 Cond:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 store i32 -987654321, i32* %A
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 br label %Cont
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 Cont:
|
95
|
67 %V = load i32, i32* %A
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 ret i32 %V
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 ; CHECK-LABEL: @test4(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 ; CHECK-NOT: alloca
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 ; CHECK: Cont:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 ; CHECK-NEXT: %storemerge = phi i32 [ -987654321, %Cond ], [ 47, %0 ]
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 ; CHECK-NEXT: ret i32 %storemerge
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 ; "if then"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 define void @test5(i1 %C, i32* %P) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 store i32 47, i32* %P, align 1
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 br i1 %C, label %Cond, label %Cont
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 Cond:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 store i32 -987654321, i32* %P, align 1
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 br label %Cont
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 Cont:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 ; CHECK-LABEL: @test5(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 ; CHECK: Cont:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 ; CHECK-NEXT: %storemerge = phi i32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 ; CHECK-NEXT: store i32 %storemerge, i32* %P, align 1
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 ; CHECK-NEXT: ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 ; PR14753 - merging two stores should preserve the TBAA tag.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 define void @test6(i32 %n, float* %a, i32* %gi) nounwind uwtable ssp {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 entry:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 store i32 42, i32* %gi, align 4, !tbaa !0
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 br label %for.cond
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 for.cond: ; preds = %for.body, %entry
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 %storemerge = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
95
|
103 %0 = load i32, i32* %gi, align 4, !tbaa !0
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 %cmp = icmp slt i32 %0, %n
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 br i1 %cmp, label %for.body, label %for.end
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 for.body: ; preds = %for.cond
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 %idxprom = sext i32 %0 to i64
|
95
|
109 %arrayidx = getelementptr inbounds float, float* %a, i64 %idxprom
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 store float 0.000000e+00, float* %arrayidx, align 4, !tbaa !3
|
95
|
111 %1 = load i32, i32* %gi, align 4, !tbaa !0
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 %inc = add nsw i32 %1, 1
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 store i32 %inc, i32* %gi, align 4, !tbaa !0
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 br label %for.cond
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 for.end: ; preds = %for.cond
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 ret void
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 ; CHECK-LABEL: @test6(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 ; CHECK: for.cond:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 ; CHECK-NEXT: phi i32 [ 42
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 ; CHECK-NEXT: store i32 %storemerge, i32* %gi, align 4, !tbaa !0
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123
|
100
|
124 define void @dse1(i32* %p) {
|
|
125 ; CHECK-LABEL: dse1
|
|
126 ; CHECK-NEXT: store
|
|
127 ; CHECK-NEXT: ret
|
|
128 store i32 0, i32* %p
|
|
129 store i32 0, i32* %p
|
|
130 ret void
|
|
131 }
|
|
132
|
|
133 ; Slightly subtle: if we're mixing atomic and non-atomic access to the
|
|
134 ; same location, then the contents of the location are undefined if there's
|
|
135 ; an actual race. As such, we're free to pick either store under the
|
|
136 ; assumption that we're not racing with any other thread.
|
|
137 define void @dse2(i32* %p) {
|
|
138 ; CHECK-LABEL: dse2
|
|
139 ; CHECK-NEXT: store i32 0, i32* %p
|
|
140 ; CHECK-NEXT: ret
|
|
141 store atomic i32 0, i32* %p unordered, align 4
|
|
142 store i32 0, i32* %p
|
|
143 ret void
|
|
144 }
|
|
145
|
|
146 define void @dse3(i32* %p) {
|
|
147 ; CHECK-LABEL: dse3
|
|
148 ; CHECK-NEXT: store atomic i32 0, i32* %p unordered, align 4
|
|
149 ; CHECK-NEXT: ret
|
|
150 store i32 0, i32* %p
|
|
151 store atomic i32 0, i32* %p unordered, align 4
|
|
152 ret void
|
|
153 }
|
|
154
|
|
155 define void @dse4(i32* %p) {
|
|
156 ; CHECK-LABEL: dse4
|
|
157 ; CHECK-NEXT: store atomic i32 0, i32* %p unordered, align 4
|
|
158 ; CHECK-NEXT: ret
|
|
159 store atomic i32 0, i32* %p unordered, align 4
|
|
160 store atomic i32 0, i32* %p unordered, align 4
|
|
161 ret void
|
|
162 }
|
|
163
|
|
164 ; Implementation limit - could remove unordered store here, but
|
|
165 ; currently don't.
|
|
166 define void @dse5(i32* %p) {
|
|
167 ; CHECK-LABEL: dse5
|
|
168 ; CHECK-NEXT: store
|
|
169 ; CHECK-NEXT: store
|
|
170 ; CHECK-NEXT: ret
|
|
171 store atomic i32 0, i32* %p unordered, align 4
|
|
172 store atomic i32 0, i32* %p seq_cst, align 4
|
|
173 ret void
|
|
174 }
|
|
175
|
|
176 define void @write_back1(i32* %p) {
|
|
177 ; CHECK-LABEL: write_back1
|
|
178 ; CHECK-NEXT: ret
|
|
179 %v = load i32, i32* %p
|
|
180 store i32 %v, i32* %p
|
|
181 ret void
|
|
182 }
|
|
183
|
|
184 define void @write_back2(i32* %p) {
|
|
185 ; CHECK-LABEL: write_back2
|
|
186 ; CHECK-NEXT: ret
|
|
187 %v = load atomic i32, i32* %p unordered, align 4
|
|
188 store i32 %v, i32* %p
|
|
189 ret void
|
|
190 }
|
|
191
|
|
192 define void @write_back3(i32* %p) {
|
|
193 ; CHECK-LABEL: write_back3
|
|
194 ; CHECK-NEXT: ret
|
|
195 %v = load i32, i32* %p
|
|
196 store atomic i32 %v, i32* %p unordered, align 4
|
|
197 ret void
|
|
198 }
|
|
199
|
|
200 define void @write_back4(i32* %p) {
|
|
201 ; CHECK-LABEL: write_back4
|
|
202 ; CHECK-NEXT: ret
|
|
203 %v = load atomic i32, i32* %p unordered, align 4
|
|
204 store atomic i32 %v, i32* %p unordered, align 4
|
|
205 ret void
|
|
206 }
|
|
207
|
|
208 ; Can't remove store due to ordering side effect
|
|
209 define void @write_back5(i32* %p) {
|
|
210 ; CHECK-LABEL: write_back5
|
|
211 ; CHECK-NEXT: load
|
|
212 ; CHECK-NEXT: store
|
|
213 ; CHECK-NEXT: ret
|
|
214 %v = load atomic i32, i32* %p unordered, align 4
|
|
215 store atomic i32 %v, i32* %p seq_cst, align 4
|
|
216 ret void
|
|
217 }
|
|
218
|
|
219 define void @write_back6(i32* %p) {
|
|
220 ; CHECK-LABEL: write_back6
|
|
221 ; CHECK-NEXT: load
|
|
222 ; CHECK-NEXT: ret
|
|
223 %v = load atomic i32, i32* %p seq_cst, align 4
|
|
224 store atomic i32 %v, i32* %p unordered, align 4
|
|
225 ret void
|
|
226 }
|
|
227
|
|
228 define void @write_back7(i32* %p) {
|
|
229 ; CHECK-LABEL: write_back7
|
|
230 ; CHECK-NEXT: load
|
|
231 ; CHECK-NEXT: ret
|
|
232 %v = load atomic volatile i32, i32* %p seq_cst, align 4
|
|
233 store atomic i32 %v, i32* %p unordered, align 4
|
|
234 ret void
|
|
235 }
|
|
236
|
83
|
237 !0 = !{!4, !4, i64 0}
|
|
238 !1 = !{!"omnipotent char", !2}
|
|
239 !2 = !{!"Simple C/C++ TBAA"}
|
|
240 !3 = !{!"float", !1}
|
|
241 !4 = !{!"int", !1}
|