Skip to content

Commit

Permalink
Merge pull request #20 from jjsuwa-sys3175/Try2AvoidUsingL32R
Browse files Browse the repository at this point in the history
GCC: Try to avoid using L32R to load 32/64bit constant
  • Loading branch information
earlephilhower authored Dec 8, 2020
2 parents b604334 + bddd2bd commit e6a192b
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
index 953f90a0..14be4081 100644
--- a/gcc/config/xtensa/xtensa.c
+++ b/gcc/config/xtensa/xtensa.c
@@ -1072,6 +1072,21 @@

if (! TARGET_AUTO_LITPOOLS && ! TARGET_CONST16)
{
+ /* Try to emit MOVI.N + SLLI sequence, that is smaller than L32R + constant pool. */
+ if (TARGET_DENSITY && mode == SImode && register_operand (dst, mode))
+ {
+ int srcval = INTVAL (src);
+ int shift;
+ if (! (srcval & 1))
+ for (srcval >>= 1, shift = 1; ! (srcval & 1) && shift < 32; srcval >>= 1, shift++)
+ if (srcval >= -32 && srcval <= 95)
+ {
+ emit_move_insn (dst, GEN_INT (srcval));
+ emit_insn (gen_ashlsi3_internal (dst, dst, GEN_INT (shift)));
+ return 1;
+ }
+ }
+
src = force_const_mem (SImode, src);
operands[1] = src;
}
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 8e304a6f..dbb36b11 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -721,8 +721,22 @@
(match_operand:DI 1 "general_operand" ""))]
""
{
- if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
- operands[1] = force_const_mem (DImode, operands[1]);
+ if (CONSTANT_P (operands[1]))
+ {
+ /* Split in halves if 64-bit Const-to-Reg moves
+ because of offering further optimization opportunities. */
+ if (register_operand (operands[0], DImode))
+ {
+ rtx first, second;
+ split_double (operands[1], &first, &second);
+ emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), first));
+ emit_insn (gen_movsi (gen_highpart (SImode, operands[0]), second));
+ DONE;
+ }
+
+ if (!TARGET_CONST16)
+ operands[1] = force_const_mem (DImode, operands[1]);
+ }

if (!register_operand (operands[0], DImode)
&& !register_operand (operands[1], DImode))
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
index 953f90a0..14be4081 100644
--- a/gcc/config/xtensa/xtensa.c
+++ b/gcc/config/xtensa/xtensa.c
@@ -1072,6 +1072,21 @@

if (! TARGET_AUTO_LITPOOLS && ! TARGET_CONST16)
{
+ /* Try to emit MOVI.N + SLLI sequence, that is smaller than L32R + constant pool. */
+ if (TARGET_DENSITY && mode == SImode && register_operand (dst, mode))
+ {
+ int srcval = INTVAL (src);
+ int shift;
+ if (! (srcval & 1))
+ for (srcval >>= 1, shift = 1; ! (srcval & 1) && shift < 32; srcval >>= 1, shift++)
+ if (srcval >= -32 && srcval <= 95)
+ {
+ emit_move_insn (dst, GEN_INT (srcval));
+ emit_insn (gen_ashlsi3_internal (dst, dst, GEN_INT (shift)));
+ return 1;
+ }
+ }
+
src = force_const_mem (SImode, src);
operands[1] = src;
}
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 8e304a6f..dbb36b11 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -721,8 +721,22 @@
(match_operand:DI 1 "general_operand" ""))]
""
{
- if (CONSTANT_P (operands[1]) && !TARGET_CONST16)
- operands[1] = force_const_mem (DImode, operands[1]);
+ if (CONSTANT_P (operands[1]))
+ {
+ /* Split in halves if 64-bit Const-to-Reg moves
+ because of offering further optimization opportunities. */
+ if (register_operand (operands[0], DImode))
+ {
+ rtx first, second;
+ split_double (operands[1], &first, &second);
+ emit_insn (gen_movsi (gen_lowpart (SImode, operands[0]), first));
+ emit_insn (gen_movsi (gen_highpart (SImode, operands[0]), second));
+ DONE;
+ }
+
+ if (!TARGET_CONST16)
+ operands[1] = force_const_mem (DImode, operands[1]);
+ }

if (!register_operand (operands[0], DImode)
&& !register_operand (operands[1], DImode))

0 comments on commit e6a192b

Please sign in to comment.