<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - a loop with a pointer increment is folded into a form that it fails to optimize further"
href="https://bugs.llvm.org/show_bug.cgi?id=41553">41553</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>a loop with a pointer increment is folded into a form that it fails to optimize further
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>Keywords</th>
<td>code-quality
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>nok.raven@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The foo should be equivalent to bar when sizeof(n) < sizeof(p)
int* foo(int* p, unsigned n)
{
for (unsigned i = 0; i < n; ++i)
++p;
return p;
}
int* bar(int* p, unsigned n)
{
p += n;
return p;
}
Produced IR:
define i32* @foo(i32* readnone, i32) {
%3 = icmp eq i32 %1, 0
%4 = add i32 %1, -1
%5 = zext i32 %4 to i64
%6 = add nuw nsw i64 %5, 1
%7 = getelementptr i32, i32* %0, i64 %6
%8 = select i1 %3, i32* %0, i32* %7
ret i32* %8
}
define i32* @bar(i32* readnone, i32) {
%3 = zext i32 %1 to i64
%4 = getelementptr inbounds i32, i32* %0, i64 %3
ret i32* %4
}
The branch looks strange, but even if I rewrite it:
Pre: C0 > 0
%a = add i32 C0, -1
%b = zext i32 %a to i64
%r = add nuw nsw i64 %b, 1
=>
%r = zext i32 C0 to i64
<a href="https://rise4fun.com/Alive/wiV">https://rise4fun.com/Alive/wiV</a>
define i32* @foo2(i32* readnone, i32) {
%3 = icmp eq i32 %1, 0
%4 = zext i32 %1 to i64
%5 = getelementptr i32, i32* %0, i64 %4
%6 = select i1 %3, i32* %0, i32* %5
ret i32* %6
}
It is not optimized further.</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>