On Sun, 27 Sept 2026 at 08:51, Mathieu Desnoyers
<[email protected]> wrote:
>
> +static __always_inline
> +int ptr_eq(const volatile void *a, const volatile void *b)
> +{
> + OPTIMIZER_HIDE_VAR(a);
> + OPTIMIZER_HIDE_VAR(b);
> + return a == b;
> +}
I had to think about why I hate this so much.
It's probably entirely senseless, but this just rubs me the wrong way.
Those OPTIMIZER_HIDE_VAR() statements are hiding the wrong thing. They
are telling the compiler to treat valid information (the pointers) as
if they had changed, so then the compiler will have to just reload
those pointers when they are used later (and "used later" is part of
the whole *point* of this, after all).
But it was never the pointer values that needed hiding from the
compiler. It's always just the comparison. And while the "optimal"
thing would be to just do something like
static __always_inline bool ptr_eq(const volatile void *a, const
volatile void *b)
{
bool ret;
asm("cmpq %0,%1":"=@ccz" (ret):"r" (a),"r"(b))
return ret;
}
that is an architecture-specific thing - and then have that
OPTIMIZER_HIDE_VAR() available as a fallback.
I don't know if it's really worth it, but I really do despise that
"hide the wrong values" thing that generates two new values just to
compare them and throw them away, and adds register pressure for no
good reason.
Linus