public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Optimize math barriers
@ 2026-05-07  2:17 Deng Jianbo
  2026-05-07  6:46 ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Deng Jianbo @ 2026-05-07  2:17 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, i.swmail
  Cc: joseph_myers, carlos, xuchenghua, Deng Jianbo

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.

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.

Example from xflow function before the change:
	movfr2gr.d      $t0, $fa0
	beqz            $a0, 12 # 69960 <xflow+0x10>
	fneg.d          $fa1, $fa0
	movfr2gr.d      $t0, $fa1
	movgr2fr.d      $fa1, $t0
	fmul.d          $fa0, $fa0, $fa1
	b               -56 # 69930 <with_errno.constprop.0>

After the patch:
	fmov.d          $fa1, $fa0
	beqz            $a0, 12 # 69ac0 <xflow+0x10>
	fneg.d          $fa1, $fa0
	nop
	fmul.d          $fa0, $fa0, $fa1
	b               -52 # 69a90 <with_errno.constprop.0>
---
 sysdeps/loongarch/fpu/math-barriers.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/loongarch/fpu/math-barriers.h b/sysdeps/loongarch/fpu/math-barriers.h
index 6a069ff41d..76835aa210 100644
--- a/sysdeps/loongarch/fpu/math-barriers.h
+++ b/sysdeps/loongarch/fpu/math-barriers.h
@@ -21,8 +21,8 @@
 
 /* Generic code forces values to memory; we don't need to do that.  */
 #define math_opt_barrier(x)					\
-  ({ __typeof (x) __x = (x); __asm ("" : "+frm" (__x)); __x; })
+  ({ __typeof (x) __x = (x); __asm ("" : "+fm" (__x)); __x; })
 #define math_force_eval(x)						\
-  ({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "frm" (__x)); })
+  ({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "fm" (__x)); })
 
 #endif /* math-barriers.h */
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-25  1:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-07  2:17 [PATCH] LoongArch: Optimize math barriers Deng Jianbo
2026-05-07  6:46 ` Andreas Schwab
2026-05-07  9:30   ` dengjianbo
2026-05-08  9:29     ` Xi Ruoyao
2026-05-08  9:47       ` dengjianbo
2026-05-25  1:09         ` dengjianbo

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).