From: dengjianbo <dengjianbo@loongson.cn>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org,
caiyinyu@loongson.cn, i.swmail@xen0n.name,
joseph_myers@mentor.com, carlos@redhat.com,
xuchenghua@loongson.cn, Xi Ruoyao <xry111@xry111.site>
Subject: Re: [PATCH] LoongArch: Optimize math barriers
Date: Thu, 7 May 2026 17:30:13 +0800 [thread overview]
Message-ID: <93c7e2b9-423b-46bf-b95c-6b456d5b1da5@loongson.cn> (raw)
In-Reply-To: <87jytf90o2.fsf@igel.home>
Yes, unnecessary moves can occur if the value is already in a general
reg. For example, when invoking math_opt_barrier with fixed-point
parameters. However, in glibc, these two macros are invoked with
floating-point parameters, and I didn’t find the unnecessary moves
being generated. For other architectures, aarch64 and s390 also do
not include the 'r' constraint.
For gcc part, to my understanding, when 'fr' is present, GCC selects the
union of FP_REGS and GR_REGS as the destination register class, which is
initialized to GR_REGS. Then compute the cost of choosing different
register classes, choosing GR_REGS incurs no extra cost, while choosing
FP_REGS adds an extra move cost. I am not sure if it's a strategy here.
On 5/7/26 2:46 PM, Andreas Schwab wrote:
> On Mai 07 2026, Deng Jianbo wrote:
>
>> The constraints 'frm' used in math_opt_barrier and math_force_eval cause
>> GCC choose fixed-point registers with lower costs in some cases, because
>> in LoongArch ira_reg_class_subunion[FP_REGS][GR_REGS] is initialized to
>> GR_REGS, extra move costs will be added when choosing FP_REGS. This
>> results in unnecessary instructions to move values between FP_REGS and
>> GR_REGS.
>
> It looks like a bug in GCC (wrong cost calculations) if it generates
> unnecessary moves when it has more choices.
>
>> Most of cases in GLIBC math barriers related macros are invoked with
>> floating-point type paramters, this patch removes "r" constraints,
>> allowing GCC to keep values in floating-point registers and avoid the
>> extra moves.
>
> It does not *allow* that, it *forces* gcc to use an fp reg (or memory).
> What if the value is in a general reg in the first place, wouldn't that
> result in unnecessary moves?
>
next prev parent reply other threads:[~2026-05-07 9:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 2:17 Deng Jianbo
2026-05-07 6:46 ` Andreas Schwab
2026-05-07 9:30 ` dengjianbo [this message]
2026-05-08 9:29 ` Xi Ruoyao
2026-05-08 9:47 ` dengjianbo
2026-05-25 1:09 ` dengjianbo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93c7e2b9-423b-46bf-b95c-6b456d5b1da5@loongson.cn \
--to=dengjianbo@loongson.cn \
--cc=adhemerval.zanella@linaro.org \
--cc=caiyinyu@loongson.cn \
--cc=carlos@redhat.com \
--cc=i.swmail@xen0n.name \
--cc=joseph_myers@mentor.com \
--cc=libc-alpha@sourceware.org \
--cc=schwab@linux-m68k.org \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).