Re: [PATCH] powerpc/bug: Remove specific powerpc BUG_ON()

From: Nicholas Piggin
Date: Thu Feb 11 2021 - 05:08:31 EST


Excerpts from Christophe Leroy's message of February 11, 2021 5:41 pm:
> powerpc BUG_ON() is based on using twnei or tdnei instruction,
> which obliges gcc to format the condition into a 0 or 1 value
> in a register.
>
> By using a generic implementation, gcc will generate a branch
> to the unconditional trap generated by BUG().

We don't want to do this on 64s because that will lose the useful CFAR
contents.

Unfortunately the code generation is not great and the registers that
give some useful information about the condition are often mangled :(

It would be nice if we could have a __builtin_trap_if that gcc would use
conditional traps with, (and which never assumes following code is
unreachable even for constant true, so we can use it with WARN and put
explicit unreachable for BUG).

>
> As modern powerpc implement branch folding, that's even more efficient.

I think POWER will speculate conditional traps as non faulting always
so it should be just as good if not better than the branch.

Thanks,
Nick