Re: [PATCH] spin loop primitives for busy waiting
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: 2017-05-12 15:56:26
Also in:
linux-arch
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: 2017-05-12 15:56:26
Also in:
linux-arch
On Fri, May 12, 2017 at 5:58 AM, David Laight [off-list ref] wrote:
At least some versions of gcc convert while (cond) do {body}
into if (cond) do {body} while (cond) even when 'cond'
is a non-trivial expression and 'body' is trivial.Afaik pretty much all versions of gcc do that, unless you use -Os (which we have effectively stopped doing because it causes so many other problems in stupid instruction choices etc).
The code-bloat is silly. No point enforcing the 'optimisation' here.
Actually, for places where we expect cold code and the loop to be
often run zero times, it actually makes sense. When we can make the
initial "if()" be unlikely, and gcc can then generate the unlikely
code all out of line, then the while -> if+do-while construction makes
sense.
It's the "normal" while loops that it's sad how big code gcc
generates, considering that most of our loop counts are vert small
(but generally nonzero).
Linus