• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -dse < %s | FileCheck %s
2target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3
4; If there are two stores to the same location, DSE should be able to remove
5; the first store if the two stores are separated by no more than 98
6; instructions. The existence of debug intrinsics between the stores should
7; not affect this instruction limit.
8
9@x = global i32 0, align 4
10
11; Function Attrs: nounwind
12define i32 @test_within_limit() !dbg !4 {
13entry:
14  ; The first store; later there is a second store to the same location,
15  ; so this store should be optimized away by DSE.
16  ; CHECK-NOT: store i32 1, i32* @x, align 4
17  store i32 1, i32* @x, align 4
18
19  ; Insert 98 dummy instructions between the two stores
20  %0 = bitcast i32 0 to i32
21  %1 = bitcast i32 0 to i32
22  %2 = bitcast i32 0 to i32
23  %3 = bitcast i32 0 to i32
24  %4 = bitcast i32 0 to i32
25  %5 = bitcast i32 0 to i32
26  %6 = bitcast i32 0 to i32
27  %7 = bitcast i32 0 to i32
28  %8 = bitcast i32 0 to i32
29  %9 = bitcast i32 0 to i32
30  %10 = bitcast i32 0 to i32
31  %11 = bitcast i32 0 to i32
32  %12 = bitcast i32 0 to i32
33  %13 = bitcast i32 0 to i32
34  %14 = bitcast i32 0 to i32
35  %15 = bitcast i32 0 to i32
36  %16 = bitcast i32 0 to i32
37  %17 = bitcast i32 0 to i32
38  %18 = bitcast i32 0 to i32
39  %19 = bitcast i32 0 to i32
40  %20 = bitcast i32 0 to i32
41  %21 = bitcast i32 0 to i32
42  %22 = bitcast i32 0 to i32
43  %23 = bitcast i32 0 to i32
44  %24 = bitcast i32 0 to i32
45  %25 = bitcast i32 0 to i32
46  %26 = bitcast i32 0 to i32
47  %27 = bitcast i32 0 to i32
48  %28 = bitcast i32 0 to i32
49  %29 = bitcast i32 0 to i32
50  %30 = bitcast i32 0 to i32
51  %31 = bitcast i32 0 to i32
52  %32 = bitcast i32 0 to i32
53  %33 = bitcast i32 0 to i32
54  %34 = bitcast i32 0 to i32
55  %35 = bitcast i32 0 to i32
56  %36 = bitcast i32 0 to i32
57  %37 = bitcast i32 0 to i32
58  %38 = bitcast i32 0 to i32
59  %39 = bitcast i32 0 to i32
60  %40 = bitcast i32 0 to i32
61  %41 = bitcast i32 0 to i32
62  %42 = bitcast i32 0 to i32
63  %43 = bitcast i32 0 to i32
64  %44 = bitcast i32 0 to i32
65  %45 = bitcast i32 0 to i32
66  %46 = bitcast i32 0 to i32
67  %47 = bitcast i32 0 to i32
68  %48 = bitcast i32 0 to i32
69  %49 = bitcast i32 0 to i32
70  %50 = bitcast i32 0 to i32
71  %51 = bitcast i32 0 to i32
72  %52 = bitcast i32 0 to i32
73  %53 = bitcast i32 0 to i32
74  %54 = bitcast i32 0 to i32
75  %55 = bitcast i32 0 to i32
76  %56 = bitcast i32 0 to i32
77  %57 = bitcast i32 0 to i32
78  %58 = bitcast i32 0 to i32
79  %59 = bitcast i32 0 to i32
80  %60 = bitcast i32 0 to i32
81  %61 = bitcast i32 0 to i32
82  %62 = bitcast i32 0 to i32
83  %63 = bitcast i32 0 to i32
84  %64 = bitcast i32 0 to i32
85  %65 = bitcast i32 0 to i32
86  %66 = bitcast i32 0 to i32
87  %67 = bitcast i32 0 to i32
88  %68 = bitcast i32 0 to i32
89  %69 = bitcast i32 0 to i32
90  %70 = bitcast i32 0 to i32
91  %71 = bitcast i32 0 to i32
92  %72 = bitcast i32 0 to i32
93  %73 = bitcast i32 0 to i32
94  %74 = bitcast i32 0 to i32
95  %75 = bitcast i32 0 to i32
96  %76 = bitcast i32 0 to i32
97  %77 = bitcast i32 0 to i32
98  %78 = bitcast i32 0 to i32
99  %79 = bitcast i32 0 to i32
100  %80 = bitcast i32 0 to i32
101  %81 = bitcast i32 0 to i32
102  %82 = bitcast i32 0 to i32
103  %83 = bitcast i32 0 to i32
104  %84 = bitcast i32 0 to i32
105  %85 = bitcast i32 0 to i32
106  %86 = bitcast i32 0 to i32
107  %87 = bitcast i32 0 to i32
108  %88 = bitcast i32 0 to i32
109  %89 = bitcast i32 0 to i32
110  %90 = bitcast i32 0 to i32
111  %91 = bitcast i32 0 to i32
112  %92 = bitcast i32 0 to i32
113  %93 = bitcast i32 0 to i32
114  %94 = bitcast i32 0 to i32
115  %95 = bitcast i32 0 to i32
116  %96 = bitcast i32 0 to i32
117  %97 = bitcast i32 0 to i32
118
119  ; Insert a meaningless dbg.value intrinsic; it should have no
120  ; effect on the working of DSE in any way.
121  call void @llvm.dbg.value(metadata i32* undef, i64 0, metadata !10, metadata !DIExpression()), !dbg !DILocation(scope: !4)
122
123  ; CHECK:  store i32 -1, i32* @x, align 4
124  store i32 -1, i32* @x, align 4
125  ret i32 0
126}
127
128; Function Attrs: nounwind
129define i32 @test_outside_limit() {
130entry:
131  ; The first store; later there is a second store to the same location
132  ; CHECK: store i32 1, i32* @x, align 4
133  store i32 1, i32* @x, align 4
134
135  ; Insert 99 dummy instructions between the two stores; this is
136  ; one too many instruction for the DSE to take place.
137  %0 = bitcast i32 0 to i32
138  %1 = bitcast i32 0 to i32
139  %2 = bitcast i32 0 to i32
140  %3 = bitcast i32 0 to i32
141  %4 = bitcast i32 0 to i32
142  %5 = bitcast i32 0 to i32
143  %6 = bitcast i32 0 to i32
144  %7 = bitcast i32 0 to i32
145  %8 = bitcast i32 0 to i32
146  %9 = bitcast i32 0 to i32
147  %10 = bitcast i32 0 to i32
148  %11 = bitcast i32 0 to i32
149  %12 = bitcast i32 0 to i32
150  %13 = bitcast i32 0 to i32
151  %14 = bitcast i32 0 to i32
152  %15 = bitcast i32 0 to i32
153  %16 = bitcast i32 0 to i32
154  %17 = bitcast i32 0 to i32
155  %18 = bitcast i32 0 to i32
156  %19 = bitcast i32 0 to i32
157  %20 = bitcast i32 0 to i32
158  %21 = bitcast i32 0 to i32
159  %22 = bitcast i32 0 to i32
160  %23 = bitcast i32 0 to i32
161  %24 = bitcast i32 0 to i32
162  %25 = bitcast i32 0 to i32
163  %26 = bitcast i32 0 to i32
164  %27 = bitcast i32 0 to i32
165  %28 = bitcast i32 0 to i32
166  %29 = bitcast i32 0 to i32
167  %30 = bitcast i32 0 to i32
168  %31 = bitcast i32 0 to i32
169  %32 = bitcast i32 0 to i32
170  %33 = bitcast i32 0 to i32
171  %34 = bitcast i32 0 to i32
172  %35 = bitcast i32 0 to i32
173  %36 = bitcast i32 0 to i32
174  %37 = bitcast i32 0 to i32
175  %38 = bitcast i32 0 to i32
176  %39 = bitcast i32 0 to i32
177  %40 = bitcast i32 0 to i32
178  %41 = bitcast i32 0 to i32
179  %42 = bitcast i32 0 to i32
180  %43 = bitcast i32 0 to i32
181  %44 = bitcast i32 0 to i32
182  %45 = bitcast i32 0 to i32
183  %46 = bitcast i32 0 to i32
184  %47 = bitcast i32 0 to i32
185  %48 = bitcast i32 0 to i32
186  %49 = bitcast i32 0 to i32
187  %50 = bitcast i32 0 to i32
188  %51 = bitcast i32 0 to i32
189  %52 = bitcast i32 0 to i32
190  %53 = bitcast i32 0 to i32
191  %54 = bitcast i32 0 to i32
192  %55 = bitcast i32 0 to i32
193  %56 = bitcast i32 0 to i32
194  %57 = bitcast i32 0 to i32
195  %58 = bitcast i32 0 to i32
196  %59 = bitcast i32 0 to i32
197  %60 = bitcast i32 0 to i32
198  %61 = bitcast i32 0 to i32
199  %62 = bitcast i32 0 to i32
200  %63 = bitcast i32 0 to i32
201  %64 = bitcast i32 0 to i32
202  %65 = bitcast i32 0 to i32
203  %66 = bitcast i32 0 to i32
204  %67 = bitcast i32 0 to i32
205  %68 = bitcast i32 0 to i32
206  %69 = bitcast i32 0 to i32
207  %70 = bitcast i32 0 to i32
208  %71 = bitcast i32 0 to i32
209  %72 = bitcast i32 0 to i32
210  %73 = bitcast i32 0 to i32
211  %74 = bitcast i32 0 to i32
212  %75 = bitcast i32 0 to i32
213  %76 = bitcast i32 0 to i32
214  %77 = bitcast i32 0 to i32
215  %78 = bitcast i32 0 to i32
216  %79 = bitcast i32 0 to i32
217  %80 = bitcast i32 0 to i32
218  %81 = bitcast i32 0 to i32
219  %82 = bitcast i32 0 to i32
220  %83 = bitcast i32 0 to i32
221  %84 = bitcast i32 0 to i32
222  %85 = bitcast i32 0 to i32
223  %86 = bitcast i32 0 to i32
224  %87 = bitcast i32 0 to i32
225  %88 = bitcast i32 0 to i32
226  %89 = bitcast i32 0 to i32
227  %90 = bitcast i32 0 to i32
228  %91 = bitcast i32 0 to i32
229  %92 = bitcast i32 0 to i32
230  %93 = bitcast i32 0 to i32
231  %94 = bitcast i32 0 to i32
232  %95 = bitcast i32 0 to i32
233  %96 = bitcast i32 0 to i32
234  %97 = bitcast i32 0 to i32
235  %98 = bitcast i32 0 to i32
236
237  ; CHECK:  store i32 -1, i32* @x, align 4
238  store i32 -1, i32* @x, align 4
239  ret i32 0
240}
241
242; Function Attrs: nounwind readnone
243declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
244
245!llvm.dbg.cu = !{!0}
246!llvm.module.flags = !{!11, !13}
247
248!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.4", isOptimized: true, emissionKind: 0, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
249!1 = !DIFile(filename: "test.c", directory: "/home/tmp")
250!2 = !{}
251!3 = !{!4}
252!4 = distinct !DISubprogram(name: "test_within_limit", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 4, file: !1, scope: !5, type: !6, variables: !2)
253!5 = !DIFile(filename: "test.c", directory: "/home/tmp")
254!6 = !DISubroutineType(types: !7)
255!7 = !{!8}
256!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
257!9 = !{!10}
258!10 = !DILocalVariable(name: "x", scope: !4, type: !8)
259!11 = !{i32 2, !"Dwarf Version", i32 4}
260!12 = !{i32* undef}
261
262!13 = !{i32 1, !"Debug Info Version", i32 3}
263