Re: [PATCH 2/4] s390/percpu: Drop unused output register from arch_this_cpu_add()

From: Alexander Gordeev

Date: Mon Oct 12 2026 - 09:42:29 EST


On Mon, Oct 12, 2026 at 01:42:47PM +0200, Heiko Carstens wrote:
> The laa/laag instructions return the old memory content, but
> arch_this_cpu_add() does not need it. Instead of allocating a dedicated
> output register old__ just to discard the returned value, change the
> val__ constraint from "d" to "+&d" so it is used as input/output
> register.
>
> This reduces register pressure.

Do you know whether the compiler is may be smart enough to select the
same register for old and val himself?

My concern is if we force the compiler to do so we might lose optimiztions
where the val could be reused after the op.

(CC-ed Ilya)

> Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
> ---
> arch/s390/include/asm/percpu.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h
> index dfab41b43b8b..fd0a3a9951ce 100644
> --- a/arch/s390/include/asm/percpu.h
> +++ b/arch/s390/include/asm/percpu.h
> @@ -188,7 +188,7 @@ do { \
> typedef typeof(pcp) pcp_op_T__; \
> union register_pair rp__; \
> pcp_op_T__ val__ = (val); \
> - pcp_op_T__ old__, *ptr__; \
> + pcp_op_T__ *ptr__; \
> \
> ptr__ = PERCPU_PTR(&(pcp)); \
> if (__builtin_constant_p(val__) && \
> @@ -209,12 +209,12 @@ do { \
> asm_inline volatile( \
> __PCPU_BEGIN("%[lcreg]","%[lcoff]","%[ptr__]", \
> "%[pair__]","%N[pair__]") \
> - op1 " %[old__],%[val__],0(%N[pair__])\n" \
> + op1 " %[val__],%[val__],0(%N[pair__])\n" \
> __PCPU_END("%[lcreg]") \
> - : [old__] "=&d" (old__), [pair__] "=&a" (rp__.pair), \
> + : [val__] "+&d" (val__), [pair__] "=&a" (rp__.pair), \
> "+m" (*ptr__), \
> "=m" (((struct lowcore *)0)->percpu_register) \
> - : [val__] "d" (val__), [ptr__] "a" (ptr__), \
> + : [ptr__] "a" (ptr__), \
> [lcreg] "i" (LC_PERCPU_REGISTER), \
> [lcoff] "i" (LC_PERCPU_OFFSET), \
> "m" (((struct lowcore *)0)->percpu_offset) \
> --
> 2.53.0
>