Re: [RFC PATCH] fs: micro-optimization remove branches by adjusting flag values

From: Al Viro
Date: Mon Sep 14 2020 - 20:31:57 EST


On Mon, Sep 14, 2020 at 07:43:38PM +0200, mateusznosek0@xxxxxxxxx wrote:
> From: Mateusz Nosek <mateusznosek0@xxxxxxxxx>
>
> When flags A and B have equal values than the following code
>
> if(flags1 & A)
> flags2 |= B;
>
> is equivalent to
>
> flags2 |= (flags1 & A);
>
> The latter code should generate less instructions and be faster as one
> branch is omitted in it.
>
> Introduced patch changes the value of 'LOOKUP_EMPTY' and makes it equal
> to the value of 'AT_EMPTY_PATH'. Thanks to that, few branches can be
> changed in a way showed above which improves both performance and the
> size of the code.

No. AT_EMPTY_PATH is a part of userland ABI; to tie LOOKUP_EMPTY to it
means that we can't ever modify the sucker. Worse, it restricts any
possible reshuffling of the LOOKUP_... bits in the future.

So unless you can show an effect on the real-world profiles, there are
fairly strong reasons to avoid that headache.