<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Do-nothing static variable not optimized out"
href="http://llvm.org/bugs/show_bug.cgi?id=17937">17937</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Do-nothing static variable not optimized out
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>htam@apple.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Clang does not optimize out a do-nothing static variable at O3. The first load
could be removed as rec_count should always be zero when the function is
called.
This program:
const int rec_limit = 30;
void foo(int& x) {
static int rec_count = 0;
if (rec_count > rec_limit) { return; }
rec_count += 1;
x = 37;
rec_count -= 1;
}
With this command:
% clang++ -S foo.cc -o - -O3 -I. -emit-llvm
Produces this output:
@_ZZ3fooRiE9rec_count = internal unnamed_addr global i32 0, align 4
; Function Attrs: nounwind uwtable
define void @_Z3fooRi(i32* nocapture %x) #0 {
%1 = load i32* @_ZZ3fooRiE9rec_count, align 4, !tbaa !0
%2 = icmp sgt i32 %1, 30
br i1 %2, label %7, label %3
; <label>:3 ; preds = %0
%4 = add nsw i32 %1, 1
store i32 %4, i32* @_ZZ3fooRiE9rec_count, align 4, !tbaa !0
store i32 37, i32* %x, align 4, !tbaa !0
%5 = load i32* @_ZZ3fooRiE9rec_count, align 4, !tbaa !0
%6 = add nsw i32 %5, -1
store i32 %6, i32* @_ZZ3fooRiE9rec_count, align 4, !tbaa !0
br label %7
; <label>:7 ; preds = %0, %3
ret void
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>