]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Optimize normal immediate data loading.
authorLulu Cheng <chenglulu@loongson.cn>
Sun, 25 May 2025 03:15:07 +0000 (11:15 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Mon, 3 Nov 2025 02:09:09 +0000 (10:09 +0800)
Ensure that only one register is used when loading immediate values.
The original immediate value load is handled through virtual
registers, resulting in the following load operation
(0x1234567890abcdef):
        lu12i.w $r4,-456004                     # 0xfffffffffff90abc
        or      $r12,$r0,$r0
        ori     $r4,$r4,3567
        lu32i.d $r12,0x45678
        lu32i.d $r4,0
        or      $r4,$r4,$r12
        lu52i.d $r4,$r4,0x123

The optimized sequence is as follows:
lu12i.w $r4,-456004 # 0xfffffffffff90abc
ori $r4,$r4,3567
lu32i.d $r4,0x45678
lu52i.d $r4,$r4,0x123

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_move_integer):
No new virtual register is allocated during immediate load.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/imm-load.c: Modify.

gcc/config/loongarch/loongarch.cc
gcc/testsuite/gcc.target/loongarch/imm-load.c

index 1dce56e46fd17daabf98d43d73b1dc0fe134fe4e..c725d028d8c3275a8677bdd146a8950c52126a57 100644 (file)
@@ -3439,13 +3439,8 @@ loongarch_move_integer (rtx temp, rtx dest, unsigned HOST_WIDE_INT value)
   x = GEN_INT (codes[0].value);
   for (i = 1; i < num_ops; i++)
     {
-      if (!can_create_pseudo_p ())
-       {
-         emit_insn (gen_rtx_SET (temp, x));
-         x = temp;
-       }
-      else
-       x = force_reg (mode, x);
+      emit_insn (gen_rtx_SET (temp, x));
+      x = temp;
 
       set_unique_reg_note (get_last_insn (), REG_EQUAL,
                           GEN_INT (codes[i-1].curr_value));
index 33291fe89bdc52673e9614852f49d037ceb6f005..a125840d5072c01ffefe628298c9f208857052a0 100644 (file)
@@ -7,5 +7,5 @@ test (void)
 {
   return 0x1234567890abcdef;
 }
-/* { dg-final { scan-rtl-dump-times "scanning new insn with uid" 6 "split1" } } */
+/* { dg-final { scan-rtl-dump-times "scanning new insn with uid" 4 "split1" } } */