[llvm-bugs] [Bug 44676] New: Missed optimization: Reverted modification of a global/thread-local that need not be visible to any external calls not optimized out
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jan 27 04:41:48 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44676
Bug ID: 44676
Summary: Missed optimization: Reverted modification of a
global/thread-local that need not be visible to any
external calls not optimized out
Product: new-bugs
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: pskocik at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
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;
}
/////////////////////////
https://gcc.godbolt.org/z/UL79D3
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200127/5d1bf814/attachment.html>
More information about the llvm-bugs
mailing list