Re: static_branch/jump_label vs branch merging
From: Segher Boessenkool
Date: Fri Apr 09 2021 - 09:06:29 EST
On Thu, Apr 08, 2021 at 06:52:18PM +0200, Peter Zijlstra wrote:
> Is there *any* way in which we can have the compiler recognise that the
> asm_goto only depends on its arguments and have it merge the branches
> itself?
>
> I do realize that asm-goto being volatile this is a fairly huge ask, but
> I figured I should at least raise the issue, if only to raise awareness.
"volatile" should not be an impediment to this at all, volatile means
there is an unspecified side effect, nothing more, nothing less. But
yes this currently does not work with GCC:
void f(int x)
{ if (x)
asm volatile("ojee %0" :: "r"(x));
else
asm volatile("ojee %0" :: "r"(x));
}
or even
static inline void h(int x)
{
asm volatile("ojee %0" :: "r"(x));
}
void f1(int x)
{ if (x)
h(x);
else
h(x);
}
which both emit silly machine code.
Segher