<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 - Using builtin_assume to optimize pointer "ptr + size / sizeof(Struct)" does not work"
href="https://bugs.llvm.org/show_bug.cgi?id=46260">46260</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Using builtin_assume to optimize pointer "ptr + size / sizeof(Struct)" does not work
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mvels@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Background: for some vector logic, I attempted to minimize the code for keeping
the distance for some 'begin' vs 'end' span.
i.e.:
void SomeFunction() {
size_type size = byte_size(begin_, end_);
begin_ = grow_or_something(begin_, ....);
end_ = add_byte_size(begin_, size);
}
auto byte_size(S* begin, S* end) {
return (end - begin) * sizeof(S);
}
auto add_byte_size(S* begin, size_t n) {
__builtin_assume((n % sizeof(S)) == 0);
return begin + n / sizeof(S);
}
The 'add_byte_size()' method refuses to do the raw add, despite my 'assume this
is a multiple of sizeof(S)'. The only think that works (reliably) is cast it
through intptr, which I'd prefer not to. (especially as the real code works
with pointer traits / pointer types making it even more verbose / boilerplate.
See examples / attempts / what works at <a href="https://gcc.godbolt.org/z/94Upor">https://gcc.godbolt.org/z/94Upor</a></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>