<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 - LLVM doesn't eliminate bounds check inside loop"
href="https://bugs.llvm.org/show_bug.cgi?id=52016">52016</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM doesn't eliminate bounds check inside loop
</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>peetlugen19@yandex.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Code:
#include <cstddef>
#include <cstdint>
struct Memory {
const uint8_t* start;
const uint8_t* end;
};
extern void panic();
#define IN_BOUNDS(p) ((p) >= global.start && (p) < global.end)
#define CHECK(a, b) do { if (!IN_BOUNDS(a) || !IN_BOUNDS(b)) { panic(); return;
} } while (0)
void cpy(const Memory global, uint8_t* dst, const uint8_t* src, size_t len) {
if (!dst || !src) {
panic();
return;
}
if (len == 0) {
return;
}
CHECK(src, src + len - 1);
CHECK(dst, dst + len - 1);
for (size_t i = 0; i < len; ++i) {
// this check is redundant
CHECK(src + i, dst + i);
dst[i] = src[i];
}
}
<a href="https://godbolt.org/z/KWro949jh">https://godbolt.org/z/KWro949jh</a>
LLVM doesn't eliminate the bounds check inside the loop.
It looks like LLVM does have a pass for exactly this problem: LoopPredication.
However it only support the experimental guard intrinsic.</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>