<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 - Missed optimization: Reverted modification of a global/thread-local that need not be visible to any external calls not optimized out"
href="https://bugs.llvm.org/show_bug.cgi?id=44676">44676</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization: Reverted modification of a global/thread-local that need not be visible to any external calls not optimized out
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>pskocik@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Gcc can very nicely optimize out modifications to global/thread objects if the
new value is only used locally (no opaque calls made) and the modification is
then reverted.
For example, for:
//_Thread_local //thread local make's clangs code better, but still not optimal
_Bool do_log;
void errlog(char const*);
static inline _Bool sadd(int A, int B, int *R)
{
if(__builtin_add_overflow(A,B,R)){
if (do_log) errlog("overflow");
return 1;
}
return 0;
}
_Bool sadd_nolog(int A,int B, int *R)
{
_Bool r;
_Bool old_log_settings=do_log; do_log=0;
r = sadd(A,B,R);
do_log=old_log_settings;
return r;
}
/////////////////////////
<a href="https://gcc.godbolt.org/z/UL79D3">https://gcc.godbolt.org/z/UL79D3</a>
gcc -Os generates an 8-byte function on x86-64 while clang -Os generates one
that's 64 bytes large.
I don't know how difficult it is to implement such an optimization, but it
would be convenient if it could be an optimization that could be counted upon.</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>