<html>
<head>
<base href="https://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 --- - We don't get rid of a loop calling strlen()"
href="https://llvm.org/bugs/show_bug.cgi?id=31302">31302</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>We don't get rid of a loop calling strlen()
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sanjoy@playingwithpointers.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Given this program:
unsigned long strlen(const char *str);
int baz(const char *s) {
int acc = 0;
for (int i = 0; i < 100; ++i)
acc += strlen(s);
return acc;
}
clang as of 288619 produces this output on -O3:
define i32 @baz(i8* nocapture readonly %s) local_unnamed_addr #0 {
entry:
%call = tail call i64 @strlen(i8* %s)
br label %for.body
for.cond.cleanup: ; preds = %for.body
%conv1 = trunc i64 %add.4 to i32
ret i32 %conv1
for.body: ; preds = %for.body, %entry
%i.08 = phi i32 [ 0, %entry ], [ %inc.4, %for.body ]
%acc.07 = phi i64 [ 0, %entry ], [ %add.4, %for.body ]
%add = add i64 %call, %acc.07
%add.1 = add i64 %call, %add
%add.2 = add i64 %call, %add.1
%add.3 = add i64 %call, %add.2
%conv6.4 = and i64 %add.3, 4294967295
%add.4 = add i64 %call, %conv6.4
%inc.4 = add nsw i32 %i.08, 5
%exitcond.4 = icmp eq i32 %inc.4, 100
br i1 %exitcond.4, label %for.cond.cleanup, label %for.body
}
which is pretty bad. Passing the above IR through opt -O3 replaces the loop
with a multiplication instruction, so this may be a pass ordering issue.</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>