|
From: | Paul Eggert |
Subject: | Re: __builtin_assume warnings |
Date: | Tue, 18 Aug 2020 15:53:54 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
On 8/18/20 12:11 AM, Mattias Engdegård wrote:
Wouldn't -Wno-assume, either locally (clang pragmas around __builtin_assume) or globally (configure?) be more effective?
No, it's the other way around at least for me: having 'assume' use Clang's __builtin_assume makes 'assume' slower. Without __builtin_assume, 'assume' falls back on __builtin_unreachable, and Clang generates better code for __builtin_unreachable than it does __builtin_assume. For the following code:
int x; static int f (void) { return x; } int g (void) { __builtin_assume (!f ()); return f (); } int h (void) { if (f ()) __builtin_unreachable (); return f (); }clang -O2 generates suboptimal machine code for g (the generated code loads from 'x') and better machine code for h (the generated code returns 0 without loading from 'x'). This is clang version 9.0.1 (Fedora 9.0.1-2.fc31) on x86_64-unknown-linux-gnu.
Perhaps someday the Clang folks will get their act together in this department, but in the meantime __builtin_unreachable is a perfectly adequate substitute.
[Prev in Thread] | Current Thread | [Next in Thread] |