Re: More annoying code generation by clang
From: Linus Torvalds
Date: Sat Apr 06 2024 - 11:40:15 EST
On Sat, 6 Apr 2024 at 05:30, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> FYI, please note that gcc-12 is able to synthesize carry-flag compares
> on its own:
Oh, gcc has been able to do that for much longer than that. It's a
idiomatic i386 pattern, and gcc has generated it for as long as I can
remember.
HOWEVER.
There's a big difference between "able to" and "GUARANTEED to".
Because this code actually requires a data-depencency and not a
control dependency as a correctness issue because of Spectre-v1.
So while I know very well that gcc _can_ do it, I also know very well
that there are absolutely no guarantees that gcc won't use a
conditional branch instead.
So this code is needs to generate good code because it's actually
important code that shows up in benchmarks, but this code also needs
to generate a very _particular_ pattern of code, and it's not good
enough that gcc may "happen" to generate that pattern of code.
Thus the inline asm.
Linus