[v0,3/4] LoongArch: Emit fewer relocations for label subtraction

Message ID 20260707174719.1883721-4-mengqinggang@loongson.cn
State New
Headers
Series Emit fewer relocations for linker relaxation |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

mengqinggang July 7, 2026, 5:47 p.m. UTC
  Mark the frag and section to indicate if they have a relaxed instruction.

For label subtraction, if there are no relaxed instructions between addsy
and subsy, do not emit relocations.
---
 gas/config/tc-loongarch.c                     | 111 ++++++-
 gas/config/tc-loongarch.h                     |  11 +
 gas/testsuite/gas/all/gas.exp                 |   2 +-
 gas/testsuite/gas/all/relax.d                 |   4 -
 gas/testsuite/gas/loongarch/insn_int32.d      | 279 +++++++++---------
 gas/testsuite/gas/loongarch/insn_int64.d      |  29 +-
 gas/testsuite/gas/loongarch/jmp_op.d          |  94 +++---
 gas/testsuite/gas/loongarch/jmp_op.s          |   2 +-
 .../gas/loongarch/la_branch_relax_1.d         | 118 ++++----
 .../gas/loongarch/la_branch_relax_1.s         |   2 +
 .../gas/loongarch/la_branch_relax_2.d         |  64 ++--
 .../gas/loongarch/la_branch_relax_2.s         |  23 +-
 gas/testsuite/gas/loongarch/relax-uleb128.d   |   9 +
 gas/testsuite/gas/loongarch/relax-uleb128.s   |  18 ++
 gas/testsuite/gas/loongarch/uleb128.d         |  36 ---
 gas/testsuite/gas/loongarch/uleb128.s         |  20 --
 ld/testsuite/ld-loongarch-elf/jmp_op.d        |  50 ----
 ld/testsuite/ld-loongarch-elf/jmp_op.s        |  23 --
 .../ld-loongarch-elf/ld-loongarch-elf.exp     |   2 -
 19 files changed, 429 insertions(+), 468 deletions(-)
 create mode 100644 gas/testsuite/gas/loongarch/relax-uleb128.d
 create mode 100644 gas/testsuite/gas/loongarch/relax-uleb128.s
 delete mode 100644 gas/testsuite/gas/loongarch/uleb128.d
 delete mode 100644 gas/testsuite/gas/loongarch/uleb128.s
 delete mode 100644 ld/testsuite/ld-loongarch-elf/jmp_op.d
 delete mode 100644 ld/testsuite/ld-loongarch-elf/jmp_op.s
  

Patch

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index de862f07a6c..ed5d47a0360 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1187,6 +1187,13 @@  move_insn (struct loongarch_cl_insn *insn, fragS *frag, long where)
 	}
     }
   install_insn (insn);
+
+  /* Mark the current section and frag as linker relaxable.  */
+  if (insn->linker_relax)
+    {
+      now_seg->sec_flg1 = true;
+      insn->frag->tc_frag_data.linker_relax = true;
+    }
 }
 
 /* Add INSN to the end of the output.  */
@@ -1598,21 +1605,57 @@  loongarch_force_relocation_sub_local (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
 	       || (S_GET_SEGMENT (fixp->fx_subsy)->flags & SEC_CODE) == 0));
 }
 
-/* Postpone text-section label subtraction calculation until linking,
-   since linker relaxations might change the deltas.  */
-bool
-loongarch_force_relocation_sub_same(fixS *fixp ATTRIBUTE_UNUSED, segT sec)
+
+/* Whether emit relocations for label subtraction in same section.  */
+static bool
+_loongarch_force_relocation_sub_same (segT sec,
+				      fragS *addfrag,
+				      fragS *subfrag)
 {
-  fragS *add_frag = symbol_get_frag (fixp->fx_addsy);
-  fragS *sub_frag = symbol_get_frag (fixp->fx_subsy);
+  if (!LARCH_opts.relax)
+    return false;
+
+  /* Not emit relocation if section has no relaxable frag.  */
+  if (!sec->sec_flg1)
+    return false;
 
   /* Not emit relocation if addsy and subsy are in the same frag.  */
-  if (add_frag == sub_frag)
+  if (addfrag == subfrag)
     return false;
 
-  return LARCH_opts.relax && (sec->flags & SEC_CODE) != 0;
+  /* Emit relocation if find a frag is relaxable from addsy to subsy.  */
+  fragS *s;
+  for (s = subfrag; s != NULL && s != addfrag; s = s->fr_next)
+    {
+      if (s->tc_frag_data.linker_relax)
+	return true;
+    }
+  if (s == addfrag)
+    return false;
+
+  for (s = addfrag; s != NULL && s != subfrag; s = s->fr_next)
+    {
+      if (s->tc_frag_data.linker_relax)
+	return true;
+    }
+  if (s == subfrag)
+    return false;
+
+  return true;
 }
 
+
+/* Postpone text-section label subtraction calculation until linking,
+   since linker relaxations might change the deltas.  */
+bool
+loongarch_force_relocation_sub_same (fixS *fixp ATTRIBUTE_UNUSED, segT sec)
+{
+  fragS *addfrag = symbol_get_frag (fixp->fx_addsy);
+  fragS *subfrag = symbol_get_frag (fixp->fx_subsy);
+  return _loongarch_force_relocation_sub_same (sec, addfrag, subfrag);
+}
+
+
 static void fix_reloc_insn (fixS *fixP, bfd_vma reloc_val, char *buf)
 {
   reloc_howto_type *howto;
@@ -1840,6 +1883,16 @@  md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
       break;
 
     case BFD_RELOC_LARCH_CFA:
+      unsigned int subtype;
+      fragS *opfrag = (fragS *) fixP->fx_frag->fr_opcode;
+      subtype = bfd_get_8 (NULL, opfrag->fr_literal + fixP->fx_where);
+
+      /* Update to the real size after relax_segment.  */
+      if (subtype == DW_CFA_advance_loc2)
+	fixP->fx_size = 2;
+      if (subtype == DW_CFA_advance_loc4)
+	fixP->fx_size = 4;
+
       if (fixP->fx_addsy && fixP->fx_subsy)
 	{
 	  fixP->fx_next = xmemdup (fixP, sizeof (*fixP), sizeof (*fixP));
@@ -1848,10 +1901,7 @@  md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	  fixP->fx_next->fx_offset = 0;
 	  fixP->fx_subsy = NULL;
 
-	  unsigned int subtype;
 	  offsetT loc;
-	  fragS *opfrag = (fragS *) fixP->fx_frag->fr_opcode;
-	  subtype = bfd_get_8 (NULL, opfrag->fr_literal + fixP->fx_where);
 	  loc = fixP->fx_frag->fr_fix - (subtype & 7);
 	  switch (subtype)
 	    {
@@ -1864,8 +1914,6 @@  md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	      break;
 
 	    case DW_CFA_advance_loc2:
-	      fixP->fx_size = 2;
-	      fixP->fx_next->fx_size = 2;
 	      fixP->fx_where = loc + 1;
 	      fixP->fx_next->fx_where = loc + 1;
 	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD16;
@@ -1874,8 +1922,6 @@  md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	      break;
 
 	    case DW_CFA_advance_loc4:
-	      fixP->fx_size = 4;
-	      fixP->fx_next->fx_size = 4;
 	      fixP->fx_where = loc;
 	      fixP->fx_next->fx_where = loc;
 	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD32;
@@ -1898,6 +1944,9 @@  md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	      break;
 	    }
 	}
+
+      if (fixP->fx_addsy == NULL)
+	fixP->fx_done = 1;
       break;
 
     case BFD_RELOC_LARCH_B16:
@@ -1917,7 +1966,10 @@  md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 
 	  /* If relax, symbol value may change at link time, so reloc need to
 	     be saved.  */
-	  if (!LARCH_opts.relax)
+	  fragS *addfrag = symbol_get_frag (fixP->fx_addsy);
+	  if (! _loongarch_force_relocation_sub_same (seg,
+						      addfrag,
+						      fixP->fx_frag))
 	    fixP->fx_done = 1;
 	}
       break;
@@ -2074,6 +2126,8 @@  loongarch_pre_output_hook (void)
 		   frag chains have been chained together.  */
 		subseg_set (s, frch->frch_subseg);
 
+		/* Set the size to 1 temporary.  The size may change in
+		   relax_segment. Update to the real size in md_apply_fix.  */
 		fix_new_exp (frag, (int) frag->fr_offset, 1, &exp, 0,
 			     BFD_RELOC_LARCH_CFA);
 	      }
@@ -2138,6 +2192,10 @@  loongarch_frag_align_code (int n, int max)
   frag_wane (frag_now);
   frag_new (0);
 
+  /* Mark the current section and frag as linker relaxable.  */
+  now_seg->sec_flg1 = true;
+  frag_now->tc_frag_data.linker_relax = true;
+
   /* If max <= 0, ignore max.
      If max >= worst_case_bytes, max has no effect.
      Similar to gas/write.c relax_segment function rs_align_code case:
@@ -2227,6 +2285,24 @@  loongarch_handle_align (fragS *fragp)
   fragp->fr_var = size;
 }
 
+
+/* Whether force relocation for label subtraction calculation,
+   sincc linker relaxation might change the deltas.  */
+
+static bool
+loongarch_force_reloc_sub (symbolS *addsy, symbolS *subsy)
+{
+  segT addsec = S_GET_SEGMENT (addsy);
+  segT subsec = S_GET_SEGMENT (subsy);
+  if (addsec != subsec)
+    return true;
+
+  fragS *addfrag = symbol_get_frag (addsy);
+  fragS *subfrag = symbol_get_frag (subsy);
+  return _loongarch_force_relocation_sub_same (addsec, addfrag, subfrag);
+}
+
+
 /* Scan uleb128 subtraction expressions and insert fixups for them.
    e.g., .uleb128 .L1 - .L0
    Because relaxation may change the value of the subtraction, we
@@ -2258,6 +2334,9 @@  loongarch_insert_uleb128_fixes (bfd *abfd ATTRIBUTE_UNUSED,
       if (fragP->fr_subtype != 0)
 	continue;
 
+      if (! loongarch_force_reloc_sub (exp->X_add_symbol, exp->X_op_symbol))
+	continue;
+
       exp_dup = xmemdup (exp, sizeof (*exp), sizeof (*exp));
       exp_dup->X_op = O_symbol;
       exp_dup->X_op_symbol = NULL;
diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h
index 5587ac1bb86..146844e772e 100644
--- a/gas/config/tc-loongarch.h
+++ b/gas/config/tc-loongarch.h
@@ -148,4 +148,15 @@  extern void loongarch_md_finish (void);
 /* The target supports Object Attributes v1.  */
 #define TC_OBJ_ATTR_v1 1
 
+
+/* Define target fragment type.  */
+#define TC_FRAG_TYPE struct loongarch_frag_type
+struct loongarch_frag_type
+{
+  bool linker_relax;
+};
+
+#define TC_FRAG_INIT(FRAGP, MAX_BYTES) \
+  do { (FRAGP)->tc_frag_data.linker_relax = false; } while (0)
+
 #endif
diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
index 940df901167..46451fb5a90 100644
--- a/gas/testsuite/gas/all/gas.exp
+++ b/gas/testsuite/gas/all/gas.exp
@@ -293,7 +293,7 @@  if {    ![istarget *c30*-*-*]
      && ![istarget h8300*-*-*]
      && ![istarget hppa*-*-*] } then {
     # msp430, mn10[23]00 and riscv emit two relocs to handle the difference of two symbols.
-    setup_xfail "am3*-*-*" "loongarch*-*-*" "mn10200-*-*" "mn10300*-*-*" "msp430*-*-*" "riscv*-*-*"
+    setup_xfail "am3*-*-*" "mn10200-*-*" "mn10300*-*-*" "msp430*-*-*" "riscv*-*-*"
     do_930509a
 }
 
diff --git a/gas/testsuite/gas/all/relax.d b/gas/testsuite/gas/all/relax.d
index 00fba6d62cd..f394043b017 100644
--- a/gas/testsuite/gas/all/relax.d
+++ b/gas/testsuite/gas/all/relax.d
@@ -4,10 +4,6 @@ 
 # because symbol values are not known until after linker relaxation has been
 # performed.
 #notarget : riscv*-*-*
-# LoongArch doesn't resolve .uleb operands that are the difference of two
-# symbols because gas write zero to object file and generate add_uleb128 and
-# sub_uleb128 reloc pair.
-#xfail: loongarch*-*-*
 
 .*: .*
 
diff --git a/gas/testsuite/gas/loongarch/insn_int32.d b/gas/testsuite/gas/loongarch/insn_int32.d
index d90dbe402c4..43a7f05be6c 100644
--- a/gas/testsuite/gas/loongarch/insn_int32.d
+++ b/gas/testsuite/gas/loongarch/insn_int32.d
@@ -2,146 +2,139 @@ 
 #objdump: -d -M no-aliases
 #skip: loongarch64-*-*
 
-.*:     file format .*
-
-
-Disassembly of section .text:
-
-0+ <.*>:
-   0:	020000a4 	slti        	\$a0, \$a1, 0
-   4:	021ffca4 	slti        	\$a0, \$a1, 2047
-   8:	022004a4 	slti        	\$a0, \$a1, -2047
-   c:	024000a4 	sltui       	\$a0, \$a1, 0
-  10:	025ffca4 	sltui       	\$a0, \$a1, 2047
-  14:	026004a4 	sltui       	\$a0, \$a1, -2047
-  18:	028000a4 	addi.w      	\$a0, \$a1, 0
-  1c:	029ffca4 	addi.w      	\$a0, \$a1, 2047
-  20:	02a004a4 	addi.w      	\$a0, \$a1, -2047
-  24:	034000a4 	andi        	\$a0, \$a1, 0x0
-  28:	035ffca4 	andi        	\$a0, \$a1, 0x7ff
-  2c:	038000a4 	ori         	\$a0, \$a1, 0x0
-  30:	039ffca4 	ori         	\$a0, \$a1, 0x7ff
-  34:	03c000a4 	xori        	\$a0, \$a1, 0x0
-  38:	03dffca4 	xori        	\$a0, \$a1, 0x7ff
-  3c:	14000004 	lu12i.w     	\$a0, 0
-  40:	14ffffe4 	lu12i.w     	\$a0, 524287
-  44:	1c000004 	pcaddu12i   	\$a0, 0
-  48:	1cffffe4 	pcaddu12i   	\$a0, 524287
-  4c:	1d000024 	pcaddu12i   	\$a0, -524287
-  50:	0004b58b 	alsl.w      	\$a7, \$t0, \$t1, 0x2
-  54:	0006b58b 	alsl.wu     	\$a7, \$t0, \$t1, 0x2
-  58:	002a0002 	break       	0x2
-  5c:	002a8002 	dbcl        	0x2
-  60:	002b0002 	syscall     	0x2
-  64:	0040898b 	slli.w      	\$a7, \$t0, 0x2
-  68:	0044898b 	srli.w      	\$a7, \$t0, 0x2
-  6c:	004889ac 	srai.w      	\$t0, \$t1, 0x2
-  70:	02048dac 	slti        	\$t0, \$t1, 291
-  74:	02448dac 	sltui       	\$t0, \$t1, 291
-  78:	02848dac 	addi.w      	\$t0, \$t1, 291
-  7c:	034009ac 	andi        	\$t0, \$t1, 0x2
-  80:	038009ac 	ori         	\$t0, \$t1, 0x2
-  84:	03c009ac 	xori        	\$t0, \$t1, 0x2
-  88:	1400246c 	lu12i.w     	\$t0, 291
-  8c:	1c00246c 	pcaddu12i   	\$t0, 291
-  90:	04048c0c 	csrrd       	\$t0, 0x123
-  94:	04048c2c 	csrwr       	\$t0, 0x123
-  98:	040009ac 	csrxchg     	\$t0, \$t1, 0x2
-  9c:	060009a2 	cacop       	0x2, \$t1, 2
-  a0:	064009ac 	lddir       	\$t0, \$t1, 0x2
-  a4:	06440980 	ldpte       	\$t0, 0x2
-  a8:	0649b9a2 	invtlb      	0x2, \$t1, \$t2
-  ac:	000060a4 	rdtimel.w   	\$a0, \$a1
-  b0:	000064a4 	rdtimeh.w   	\$a0, \$a1
-  b4:	000418a4 	alsl.w      	\$a0, \$a1, \$a2, 0x1
-  b8:	000598a4 	alsl.w      	\$a0, \$a1, \$a2, 0x4
-  bc:	000618a4 	alsl.wu     	\$a0, \$a1, \$a2, 0x1
-  c0:	000798a4 	alsl.wu     	\$a0, \$a1, \$a2, 0x4
-  c4:	001018a4 	add.w       	\$a0, \$a1, \$a2
-  c8:	001118a4 	sub.w       	\$a0, \$a1, \$a2
-  cc:	001218a4 	slt         	\$a0, \$a1, \$a2
-  d0:	001298a4 	sltu        	\$a0, \$a1, \$a2
-  d4:	001418a4 	nor         	\$a0, \$a1, \$a2
-  d8:	001498a4 	and         	\$a0, \$a1, \$a2
-  dc:	001518a4 	or          	\$a0, \$a1, \$a2
-  e0:	001598a4 	xor         	\$a0, \$a1, \$a2
-  e4:	001718a4 	sll.w       	\$a0, \$a1, \$a2
-  e8:	001798a4 	srl.w       	\$a0, \$a1, \$a2
-  ec:	001818a4 	sra.w       	\$a0, \$a1, \$a2
-  f0:	001c18a4 	mul.w       	\$a0, \$a1, \$a2
-  f4:	001c98a4 	mulh.w      	\$a0, \$a1, \$a2
-  f8:	001d18a4 	mulh.wu     	\$a0, \$a1, \$a2
-  fc:	002018a4 	div.w       	\$a0, \$a1, \$a2
- 100:	002098a4 	mod.w       	\$a0, \$a1, \$a2
- 104:	002118a4 	div.wu      	\$a0, \$a1, \$a2
- 108:	002198a4 	mod.wu      	\$a0, \$a1, \$a2
- 10c:	002a0000 	break       	0x0
- 110:	002a7fff 	break       	0x7fff
- 114:	002a8000 	dbcl        	0x0
- 118:	002affff 	dbcl        	0x7fff
- 11c:	004080a4 	slli.w      	\$a0, \$a1, 0x0
- 120:	004084a4 	slli.w      	\$a0, \$a1, 0x1
- 124:	0040fca4 	slli.w      	\$a0, \$a1, 0x1f
- 128:	004480a4 	srli.w      	\$a0, \$a1, 0x0
- 12c:	004484a4 	srli.w      	\$a0, \$a1, 0x1
- 130:	0044fca4 	srli.w      	\$a0, \$a1, 0x1f
- 134:	004880a4 	srai.w      	\$a0, \$a1, 0x0
- 138:	004884a4 	srai.w      	\$a0, \$a1, 0x1
- 13c:	0048fca4 	srai.w      	\$a0, \$a1, 0x1f
- 140:	200000a4 	ll.w        	\$a0, \$a1, 0
- 144:	203ffca4 	ll.w        	\$a0, \$a1, 16380
- 148:	210000a4 	sc.w        	\$a0, \$a1, 0
- 14c:	213ffca4 	sc.w        	\$a0, \$a1, 16380
- 150:	280000a4 	ld.b        	\$a0, \$a1, 0
- 154:	281ffca4 	ld.b        	\$a0, \$a1, 2047
- 158:	282004a4 	ld.b        	\$a0, \$a1, -2047
- 15c:	284000a4 	ld.h        	\$a0, \$a1, 0
- 160:	285ffca4 	ld.h        	\$a0, \$a1, 2047
- 164:	286004a4 	ld.h        	\$a0, \$a1, -2047
- 168:	288000a4 	ld.w        	\$a0, \$a1, 0
- 16c:	289ffca4 	ld.w        	\$a0, \$a1, 2047
- 170:	28a004a4 	ld.w        	\$a0, \$a1, -2047
- 174:	290000a4 	st.b        	\$a0, \$a1, 0
- 178:	291ffca4 	st.b        	\$a0, \$a1, 2047
- 17c:	292004a4 	st.b        	\$a0, \$a1, -2047
- 180:	294000a4 	st.h        	\$a0, \$a1, 0
- 184:	295ffca4 	st.h        	\$a0, \$a1, 2047
- 188:	296004a4 	st.h        	\$a0, \$a1, -2047
- 18c:	298000a4 	st.w        	\$a0, \$a1, 0
- 190:	299ffca4 	st.w        	\$a0, \$a1, 2047
- 194:	29a004a4 	st.w        	\$a0, \$a1, -2047
- 198:	2a0000a4 	ld.bu       	\$a0, \$a1, 0
- 19c:	2a1ffca4 	ld.bu       	\$a0, \$a1, 2047
- 1a0:	2a2004a4 	ld.bu       	\$a0, \$a1, -2047
- 1a4:	2a4000a4 	ld.hu       	\$a0, \$a1, 0
- 1a8:	2a5ffca4 	ld.hu       	\$a0, \$a1, 2047
- 1ac:	2a6004a4 	ld.hu       	\$a0, \$a1, -2047
- 1b0:	2ac000a0 	preld       	0x0, \$a1, 0
- 1b4:	2adffcbf 	preld       	0x1f, \$a1, 2047
- 1b8:	2ae004bf 	preld       	0x1f, \$a1, -2047
- 1bc:	385714c4 	sc.q        	\$a0, \$a1, \$a2
- 1c0:	385714c4 	sc.q        	\$a0, \$a1, \$a2
- 1c4:	385780a4 	llacq.w     	\$a0, \$a1
- 1c8:	385780a4 	llacq.w     	\$a0, \$a1
- 1cc:	385784a4 	screl.w     	\$a0, \$a1
- 1d0:	385784a4 	screl.w     	\$a0, \$a1
- 1d4:	38720000 	dbar        	0x0
- 1d8:	38727fff 	dbar        	0x7fff
- 1dc:	38728000 	ibar        	0x0
- 1e0:	3872ffff 	ibar        	0x7fff
-
-0+1e4 <.L1>:
- 1e4:	03400000 	andi        	\$zero, \$zero, 0x0
- 1e8:	53ffffff 	b           	-4	# 1e4 <.L1>
- 1ec:	57fffbff 	bl          	-8	# 1e4 <.L1>
- 1f0:	5bfff485 	beq         	\$a0, \$a1, -12	# 1e4 <.L1>
- 1f4:	5ffff085 	bne         	\$a0, \$a1, -16	# 1e4 <.L1>
- 1f8:	63ffec85 	blt         	\$a0, \$a1, -20	# 1e4 <.L1>
- 1fc:	63ffe8a4 	blt         	\$a1, \$a0, -24	# 1e4 <.L1>
- 200:	67ffe485 	bge         	\$a0, \$a1, -28	# 1e4 <.L1>
- 204:	67ffe0a4 	bge         	\$a1, \$a0, -32	# 1e4 <.L1>
- 208:	6bffdc85 	bltu        	\$a0, \$a1, -36	# 1e4 <.L1>
- 20c:	6bffd8a4 	bltu        	\$a1, \$a0, -40	# 1e4 <.L1>
- 210:	6fffd485 	bgeu        	\$a0, \$a1, -44	# 1e4 <.L1>
- 214:	6fffd0a4 	bgeu        	\$a1, \$a0, -48	# 1e4 <.L1>
- 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4[ 	]+bgeu[ 	]+\$a1,[ 	]+\$a0,[ 	]+-48[ 	]+#[ 	]+1e4[ 	]+<a\+0xc1>
+[ 	]+218:[ 	]+4c000080[ 	]+jirl[ 	]+\$zero,[ 	]+\$a0,[ 	]+0
diff --git a/gas/testsuite/gas/loongarch/insn_int64.d b/gas/testsuite/gas/loongarch/insn_int64.d
index 360b840d415..dcfeaac8e52 100644
--- a/gas/testsuite/gas/loongarch/insn_int64.d
+++ b/gas/testsuite/gas/loongarch/insn_int64.d
@@ -411,20 +411,19 @@  Disassembly of section .text:
  640:	385f94c4 	amadd_db.h  	\$a0, \$a1, \$a2
  644:	385f98a4 	amadd_db.h  	\$a0, \$a2, \$a1
 
-0+648 <.L1>:
  648:	03400000 	andi        	\$zero, \$zero, 0x0
- 64c:	43fffc9f 	beqz        	\$a0, -4	# 648 <.L1>
- 650:	47fff89f 	bnez        	\$a0, -8	# 648 <.L1>
- 654:	53fff7ff 	b           	-12	# 648 <.L1>
- 658:	57fff3ff 	bl          	-16	# 648 <.L1>
- 65c:	5bffec85 	beq         	\$a0, \$a1, -20	# 648 <.L1>
- 660:	5fffe885 	bne         	\$a0, \$a1, -24	# 648 <.L1>
- 664:	63ffe485 	blt         	\$a0, \$a1, -28	# 648 <.L1>
- 668:	63ffe0a4 	blt         	\$a1, \$a0, -32	# 648 <.L1>
- 66c:	67ffdc85 	bge         	\$a0, \$a1, -36	# 648 <.L1>
- 670:	67ffd8a4 	bge         	\$a1, \$a0, -40	# 648 <.L1>
- 674:	6bffd485 	bltu        	\$a0, \$a1, -44	# 648 <.L1>
- 678:	6bffd0a4 	bltu        	\$a1, \$a0, -48	# 648 <.L1>
- 67c:	6fffcc85 	bgeu        	\$a0, \$a1, -52	# 648 <.L1>
- 680:	6fffc8a4 	bgeu        	\$a1, \$a0, -56	# 648 <.L1>
+ 64c:	43fffc9f 	beqz        	\$a0, -4.*
+ 650:	47fff89f 	bnez        	\$a0, -8.*
+ 654:	53fff7ff 	b           	-12.*
+ 658:	57fff3ff 	bl          	-16.*
+ 65c:	5bffec85 	beq         	\$a0, \$a1, -20.*
+ 660:	5fffe885 	bne         	\$a0, \$a1, -24.*
+ 664:	63ffe485 	blt         	\$a0, \$a1, -28.*
+ 668:	63ffe0a4 	blt         	\$a1, \$a0, -32.*
+ 66c:	67ffdc85 	bge         	\$a0, \$a1, -36.*
+ 670:	67ffd8a4 	bge         	\$a1, \$a0, -40.*
+ 674:	6bffd485 	bltu        	\$a0, \$a1, -44.*
+ 678:	6bffd0a4 	bltu        	\$a1, \$a0, -48.*
+ 67c:	6fffcc85 	bgeu        	\$a0, \$a1, -52.*
+ 680:	6fffc8a4 	bgeu        	\$a1, \$a0, -56.*
  684:	4c000080 	jirl        	\$zero, \$a0, 0
diff --git a/gas/testsuite/gas/loongarch/jmp_op.d b/gas/testsuite/gas/loongarch/jmp_op.d
index 21576072aab..1a552b2c7b5 100644
--- a/gas/testsuite/gas/loongarch/jmp_op.d
+++ b/gas/testsuite/gas/loongarch/jmp_op.d
@@ -1,50 +1,48 @@ 
-#as:
+#as: -mrelax
 #objdump: -dr
 
-.*:[    ]+file format .*
-
-
-Disassembly of section .text:
-
-00000000.* <.L1>:
-[ 	]+0:[ 	]+03400000[ 	]+nop
-[ 	]+4:[ 	]+63fffc04[ 	]+bgtz[ 	]+\$a0,[ 	]+-4[ 	]+#[ 	]+0[ 	]+<\.L1>
-[ 	]+4:[ 	]+R_LARCH_B16[ 	]+\.L1
-[ 	]+8:[ 	]+67fff880[ 	]+bgez[ 	]+\$a0,[ 	]+-8[ 	]+#[ 	]+0[ 	]+<\.L1>
-[ 	]+8:[ 	]+R_LARCH_B16[ 	]+\.L1
-[ 	]+c:[ 	]+67fff404[ 	]+blez[ 	]+\$a0,[ 	]+-12[ 	]+#[ 	]+0[ 	]+<\.L1>
-[ 	]+c:[ 	]+R_LARCH_B16[ 	]+\.L1
-[ 	]+10:[ 	]+43fff09f[ 	]+beqz[ 	]+\$a0,[ 	]+-16[ 	]+#[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0[ 	]+<.L1>
+[ 	]+50:[ 	]+R_LARCH_B16[ 	]+.L1
+[ 	]+54:[ 	]+6fffaca4[ 	]+bgeu[ 	]+\$a1,[ 	]+\$a0,[ 	]+-84[ 	]+#[ 	]+0[ 	]+<.L1>
+[ 	]+54:[ 	]+R_LARCH_B16[ 	]+.L1
+[ 	]+58:[ 	]+4c000020[ 	]+ret
diff --git a/gas/testsuite/gas/loongarch/jmp_op.s b/gas/testsuite/gas/loongarch/jmp_op.s
index 56f986784e2..9630ca82a6f 100644
--- a/gas/testsuite/gas/loongarch/jmp_op.s
+++ b/gas/testsuite/gas/loongarch/jmp_op.s
@@ -1,5 +1,5 @@ 
 .L1:
-nop
+call36 .L1
 bgtz  $r4,.L1
 bgez  $r4,.L1
 blez  $r4,.L1
diff --git a/gas/testsuite/gas/loongarch/la_branch_relax_1.d b/gas/testsuite/gas/loongarch/la_branch_relax_1.d
index 7984b6dfca5..b2c90641267 100644
--- a/gas/testsuite/gas/loongarch/la_branch_relax_1.d
+++ b/gas/testsuite/gas/loongarch/la_branch_relax_1.d
@@ -1,64 +1,58 @@ 
-#as:
+#as: -mrelax
 #objdump: -dr
 
-.*:[    ]+file format .*
-
-
-Disassembly of section .text:
-
-0* <.L1>:
-[ 	]+...
-[ 	]+48d158:[ 	]+5c00098d[ 	]+bne[ 	]+\$t0, \$t1, 8[ 	]+# 48d160 <.L1\+0x48d160>
-[ 	]+48d15c:[ 	]+532ea7ed[ 	]+b[ 	]+-4772188[ 	]+# 0 <.L1>
-[ 	]+48d15c: R_LARCH_B26[ 	]+.L1
-[ 	]+48d160:[ 	]+5800098d[ 	]+beq[ 	]+\$t0, \$t1, 8[ 	]+# 48d168 <.L1\+0x48d168>
-[ 	]+48d164:[ 	]+532e9fed[ 	]+b[ 	]+-4772196[ 	]+# 0 <.L1>
-[ 	]+48d164: R_LARCH_B26[ 	]+.L1
-[ 	]+48d168:[ 	]+6400098d[ 	]+bge[ 	]+\$t0, \$t1, 8[ 	]+# 48d170 <.L1\+0x48d170>
-[ 	]+48d16c:[ 	]+532e97ed[ 	]+b[ 	]+-4772204[ 	]+# 0 <.L1>
-[ 	]+48d16c: R_LARCH_B26[ 	]+.L1
-[ 	]+48d170:[ 	]+640009ac[ 	]+bge[ 	]+\$t1, \$t0, 8[ 	]+# 48d178 <.L1\+0x48d178>
-[ 	]+48d174:[ 	]+532e8fed[ 	]+b[ 	]+-4772212[ 	]+# 0 <.L1>
-[ 	]+48d174: R_LARCH_B26[ 	]+.L1
-[ 	]+48d178:[ 	]+64000980[ 	]+bgez[ 	]+\$t0, 8[ 	]+# 48d180 <.L1\+0x48d180>
-[ 	]+48d17c:[ 	]+532e87ed[ 	]+b[ 	]+-4772220[ 	]+# 0 <.L1>
-[ 	]+48d17c: R_LARCH_B26[ 	]+.L1
-[ 	]+48d180:[ 	]+6400080c[ 	]+blez[ 	]+\$t0, 8[ 	]+# 48d188 <.L1\+0x48d188>
-[ 	]+48d184:[ 	]+532e7fed[ 	]+b[ 	]+-4772228[ 	]+# 0 <.L1>
-[ 	]+48d184: R_LARCH_B26[ 	]+.L1
-[ 	]+48d188:[ 	]+600009ac[ 	]+blt[ 	]+\$t1, \$t0, 8[ 	]+# 48d190 <.L1\+0x48d190>
-[ 	]+48d18c:[ 	]+532e77ed[ 	]+b[ 	]+-4772236[ 	]+# 0 <.L1>
-[ 	]+48d18c: R_LARCH_B26[ 	]+.L1
-[ 	]+48d190:[ 	]+6000098d[ 	]+blt[ 	]+\$t0, \$t1, 8[ 	]+# 48d198 <.L1\+0x48d198>
-[ 	]+48d194:[ 	]+532e6fed[ 	]+b[ 	]+-4772244[ 	]+# 0 <.L1>
-[ 	]+48d194: R_LARCH_B26[ 	]+.L1
-[ 	]+48d198:[ 	]+6000080c[ 	]+bgtz[ 	]+\$t0, 8[ 	]+# 48d1a0 <.L1\+0x48d1a0>
-[ 	]+48d19c:[ 	]+532e67ed[ 	]+b[ 	]+-4772252[ 	]+# 0 <.L1>
-[ 	]+48d19c: R_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a1774c41 100644
--- a/gas/testsuite/gas/loongarch/la_branch_relax_1.s
+++ b/gas/testsuite/gas/loongarch/la_branch_relax_1.s
@@ -1,8 +1,10 @@ 
 # Instruction and Relocation generating tests
 
+.text
 .L1:
   .fill 0x123456, 4, 0x0
 
+  call .L1
 # R_LARCH_B16
   beq $r12, $r13, .L1
   bne $r12, $r13, .L1
diff --git a/gas/testsuite/gas/loongarch/la_branch_relax_2.d b/gas/testsuite/gas/loongarch/la_branch_relax_2.d
index 4a3c6384d9c..00357d10cb3 100644
--- a/gas/testsuite/gas/loongarch/la_branch_relax_2.d
+++ b/gas/testsuite/gas/loongarch/la_branch_relax_2.d
@@ -1,40 +1,28 @@ 
-#as:
+#as: -mrelax
 #objdump: -dr
 
-.*:[    ]+file format .*
-
-
-Disassembly of section .text:
-
-0* <.L1>:
-[ 	]+...
-[ 	]+20000:[ 	]+5a00018d[ 	]+beq[ 	]+\$t0, \$t1, -131072[ 	]+# 0 <.L1>
-[ 	]+20000: R_LARCH_B16[ 	]+.L1
-[ 	]+20004:[ 	]+5c00098d[ 	]+bne[ 	]+\$t0, \$t1, 8[ 	]+# 2000c <.L1\+0x2000c>
-[ 	]+20008:[ 	]+51fffbff[ 	]+b[ 	]+-131080[ 	]+# 0 <.L1>
-[ 	]+20008: R_LARCH_B26[ 	]+.L1
-[ 	]+2000c:[ 	]+5c00098d[ 	]+bne[ 	]+\$t0, \$t1, 8[ 	]+# 20014 <.L1\+0x20014>
-[ 	]+20010:[ 	]+52000000[ 	]+b[ 	]+131072[ 	]+# 40010 <.L2>
-[ 	]+20010: R_LARCH_B26[ 	]+.L2
-[ 	]+20014:[ 	]+59fffd8d[ 	]+beq[ 	]+\$t0, \$t1, 131068[ 	]+# 40010 <.L2>
-[ 	]+20014: R_LARCH_B16[ 	]+.L2
-[ 	]+...
-0*40010 <.L2>:
-[ 	]+...
-[ 	]+440010:[ 	]+40000190[ 	]+beqz[ 	]+\$t0, -4194304[ 	]+# 40010 <.L2>
-[ 	]+440010: R_LARCH_B21[ 	]+.L2
-[ 	]+440014:[ 	]+44000980[ 	]+bnez[ 	]+\$t0, 8[ 	]+# 44001c <.L2\+0x40000c>
-[ 	]+440018:[ 	]+53fffbef[ 	]+b[ 	]+-4194312[ 	]+# 40010 <.L2>
-[ 	]+440018: R_LARCH_B26[ 	]+.L2
-[ 	]+44001c:[ 	]+44000980[ 	]+bnez[ 	]+\$t0, 8[ 	]+# 440024 <.L2\+0x400014>
-[ 	]+440020:[ 	]+50000010[ 	]+b[ 	]+4194304[ 	]+# 840020 <.L3>
-[ 	]+440020: R_LARCH_B26[ 	]+.L3
-[ 	]+440024:[ 	]+43fffd8f[ 	]+beqz[ 	]+\$t0, 4194300[ 	]+# 840020 <.L3>
-[ 	]+440024: R_LARCH_B21[ 	]+.L3
-[ 	]+...
-0*840020 <.L3>:
-[ 	]+840020:[ 	]+5800018d[ 	]+beq[ 	]+\$t0, \$t1, 0[ 	]+# 840020 <.L3>
-[ 	]+840020: R_LARCH_B16[ 	]+.L4
-0*840024 <.L5>:
-[ 	]+840024:[ 	]+40000180[ 	]+beqz[ 	]+\$t0, 0[ 	]+# 840024 <.L5>
-[ 	]+840024: R_LARCH_B21[ 	]+.L5
+#...
+.*beq.*
+.*R_LARCH_B16.*
+.*bne.*
+.*b .*
+.*R_LARCH_B26.*
+.*bne.*
+.*b .*
+.*R_LARCH_B26.*
+.*beq.*
+.*R_LARCH_B16.*
+#...
+.*beqz.*
+.*R_LARCH_B21.*
+.*bnez.*
+.*b .*
+.*R_LARCH_B26.*
+.*bnez.*
+.*b .*
+.*R_LARCH_B26.*
+.*beqz.*
+.*R_LARCH_B21.*
+#...
+.*beq.*t0.*t1, 0.*
+.*beqz.*t0, 0.*
diff --git a/gas/testsuite/gas/loongarch/la_branch_relax_2.s b/gas/testsuite/gas/loongarch/la_branch_relax_2.s
index 3e6c5534315..76ccc043a41 100644
--- a/gas/testsuite/gas/loongarch/la_branch_relax_2.s
+++ b/gas/testsuite/gas/loongarch/la_branch_relax_2.s
@@ -1,22 +1,27 @@ 
 # Immediate boundary value tests
 
+.text
 .L1:
-  .fill 0x8000, 4, 0
+  .fill 0x7ffe, 4, 0
+  call .L1
   beq $r12, $r13, .L1 # min imm -0x20000
-  beq $r12, $r13, .L1 # out of range
-  beq $r12, $r13, .L2 # out of range
+  beq $r12, $r13, .L1 # out of range, chang to bne+b
+  beq $r12, $r13, .L2 # out of range, change to bne+b
   beq $r12, $r13, .L2 # max imm 0x1fffc
-  .fill 0x7ffe, 4, 0
+  call .L1
+  .fill 0x7ffc, 4, 0
 .L2:
-  .fill 0x100000, 4, 0
+  .fill 0xffffe, 4, 0
+  call .L1
   beqz $r12, .L2 # min imm -0x400000
-  beqz $r12, .L2 # out of range
-  beqz $r12, .L3 # out of range
+  beqz $r12, .L2 # out of range, change to bnez+b
+  beqz $r12, .L3 # out of range, change to bnez+b
   beqz $r12, .L3 # max imm 0x3ffffc
-  .fill 0xffffe, 4, 0
+  call .L1
+  .fill 0xffffc, 4, 0
 .L3:
 
-# 0 imm
+# 0 imm: branch target is current pc
 .L4:
   beq $r12, $r13, .L4
 .L5:
diff --git a/gas/testsuite/gas/loongarch/relax-uleb128.d b/gas/testsuite/gas/loongarch/relax-uleb128.d
new file mode 100644
index 00000000000..720caf22e00
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/relax-uleb128.d
@@ -0,0 +1,9 @@ 
+#source: relax-uleb128.s
+#as: -mrelax
+#readelf: -rW
+
+#...
+.*R_LARCH_ADD_ULEB128.*10.*L2.*
+.*R_LARCH_SUB_ULEB128.*00.*L1.*
+.*R_LARCH_ADD_ULEB128.*1c.*L3.*
+.*R_LARCH_SUB_ULEB128.*10.*L2.*
diff --git a/gas/testsuite/gas/loongarch/relax-uleb128.s b/gas/testsuite/gas/loongarch/relax-uleb128.s
new file mode 100644
index 00000000000..cc5ffe48520
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/relax-uleb128.s
@@ -0,0 +1,18 @@ 
+.text
+.L1:
+  nop
+  call .L1
+  nop
+.L2:
+  nop
+  .p2align 3
+  nop
+.L3:
+  nop
+.L4:
+  nop
+
+.data
+  .uleb128 .L2-.L1 # Emit add/sub uleb128 relocs.
+  .uleb128 .L3-.L2 # Emit add/sub uleb128 relocs.
+  .uleb128 .L4-.L3 # Not emit add/sub uleb128 relocs.
diff --git a/gas/testsuite/gas/loongarch/uleb128.d b/gas/testsuite/gas/loongarch/uleb128.d
deleted file mode 100644
index 1a6730f3aab..00000000000
--- a/gas/testsuite/gas/loongarch/uleb128.d
+++ /dev/null
@@ -1,36 +0,0 @@ 
-#as:
-#objdump: -Dr
-#skip: loongarch32-*-*
-
-.*:[    ]+file format .*
-
-
-Disassembly of section .data:
-
-00000000.* <L1-0x5>:
-[ 	]*0:[ 	]*80030201[ 	]*\.word[ 	]*0x80030201
-[ 	]*3:[ 	]*R_LARCH_ADD_ULEB128[ 	]*L2
-[ 	]*3:[ 	]*R_LARCH_SUB_ULEB128[ 	]*L1
-[ 	]*\.\.\.
-
-[ 	]*0000000000000005[ 	]*<L1>:
-[ 	]*\.\.\.
-[ 	]*81:[ 	]*ff040000[ 	]*\.word[ 	]*0xff040000
-[ 	]*85:[ 	]*cacop[ 	]*0x1f,[ 	]*\$t3,[ 	]*1
-
-[ 	]*0000000000000086[ 	]*<L2>:
-[ 	]*86:[ 	]*07060005[ 	]*\.word[ 	]*0x07060005
-[ 	]*8a:[ 	]*x86inc\.b[ 	]*\$a0
-[ 	]*8a:[ 	]*R_LARCH_ADD_ULEB128[ 	]*L4
-[ 	]*8a:[ 	]*R_LARCH_SUB_ULEB128[ 	]*L3
-
-[ 	]*000000000000008d[ 	]*<L3>:
-[ 	]*\.\.\.
-[ 	]*4089:[ 	]*ff080000[ 	]*\.word[ 	]*0xff080000
-[ 	]*408d:[ 	]*\.word[ 	]*0x09ffffff
-
-[ 	]*0000000000004090[ 	]*<L4>:
-[ 	]*4090:[ 	]*09090909[ 	]*\.word[ 	]*0x09090909
-[ 	]*4094:[ 	]*09090909[ 	]*\.word[ 	]*0x09090909
-[ 	]*4098:[ 	]*09090909[ 	]*\.word[ 	]*0x09090909
-[ 	]*409c:[ 	]*09090909[ 	]*\.word[ 	]*0x09090909
diff --git a/gas/testsuite/gas/loongarch/uleb128.s b/gas/testsuite/gas/loongarch/uleb128.s
deleted file mode 100644
index 104a8956bd6..00000000000
--- a/gas/testsuite/gas/loongarch/uleb128.s
+++ /dev/null
@@ -1,20 +0,0 @@ 
- .data
- .byte 1, 2, 3
- .uleb128 L2 - L1
-L1:
- .space 128 - 2
- .byte 4
- .p2align 1, 0xff
-L2:
- .byte 5
-
- .p2align 2
- .byte 6, 7
- .uleb128 L4 - L3
-L3:
- .space 128*128 - 2
- .byte 8
- .p2align 2, 0xff
-L4:
- .byte 9
- .p2align 4, 9
diff --git a/ld/testsuite/ld-loongarch-elf/jmp_op.d b/ld/testsuite/ld-loongarch-elf/jmp_op.d
deleted file mode 100644
index 231d780923e..00000000000
--- a/ld/testsuite/ld-loongarch-elf/jmp_op.d
+++ /dev/null
@@ -1,50 +0,0 @@ 
-#as:
-#objdump: -dr -M no-aliases
-
-.*:[    ]+file format .*
-
-
-Disassembly of section .text:
-
-00000000.* <.L1>:
-[ 	]+0:[ 	]+03400000[ 	]+andi[ 	]+\$zero,[ 	]+\$zero,[ 	]+0x0
-[ 	]+4:[ 	]+63fffc04[ 	]+blt[ 	]+\$zero,[ 	]+\$a0,[ 	]+-4[ 	]+#[ 	]+0[ 	]+<.L1>
-[ 	]+4:[ 	]+R_LARCH_B16[ 	]+.L1
-[ 	]+8:[ 	]+67fff880[ 	]+bge[ 	]+\$a0,[ 	]+\$zero,[ 	]+-8[ 	]+#[ 	]+0[ 	]+<.L1>
-[ 	]+8:[ 	]+R_LARCH_B16[ 	]+.L1
-[ 	]+c:[ 	]+67fff404[ 	]+bge[ 	]+\$zero,[ 	]+\$a0,[ 	]+-12[ 	]+#[ 	]+0[ 	]+<.L1>
-[ 	]+c:[ 	]+R_LARCH_B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000
--- a/ld/testsuite/ld-loongarch-elf/jmp_op.s
+++ /dev/null
@@ -1,23 +0,0 @@ 
-.L1:
-nop
-bgtz  $r4,.L1
-bgez  $r4,.L1
-blez  $r4,.L1
-beqz  $r4,.L1
-bnez  $r4,.L1
-bceqz  $fcc0,.L1
-bcnez  $fcc0,.L1
-jr  $r4
-b  .L1
-bl  .L1
-beq  $r4,$r5,.L1
-bne  $r4,$r5,.L1
-blt  $r4,$r5,.L1
-bgt  $r4,$r5,.L1
-bge  $r4,$r5,.L1
-ble  $r4,$r5,.L1
-bltu  $r4,$r5,.L1
-bgtu  $r4,$r5,.L1
-bgeu  $r4,$r5,.L1
-bleu  $r4,$r5,.L1
-ret
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
index d702e5138c6..ce1bf651b5a 100644
--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
+++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
@@ -20,7 +20,6 @@ 
 #
 
 if [istarget "loongarch64-*-*"] {
-    run_dump_test "jmp_op"
     run_dump_test "macro_op"
     run_dump_test "syscall"
     run_dump_test "disas-jirl"
@@ -58,7 +57,6 @@  if [istarget "loongarch64-*-*"] {
 }
 
 if [istarget "loongarch32-*-*"] {
-    run_dump_test "jmp_op"
     run_dump_test "macro_op_32"
     run_dump_test "syscall"
     run_dump_test "disas-jirl-32"