LA32 does not support stptr/ldptr instructions. Change stptr/ldptr
to st/ld when imm is 0.

stptr.w $r27,$r3,0 -> st.w $r27,$r3,0
ldptr.w $r27,$r3,0 -> ld.w $r27,$r3,0

gcc/ChangeLog:

        * config/loongarch/loongarch.cc (loongarch_output_move): If
        GET_CODE(XEXP (src, 0)) == REG, use ld/st instead.
---
 gcc/config/loongarch/loongarch.cc | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index c1941999962..adc37b53d48 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -5120,10 +5120,14 @@ loongarch_output_move (rtx *operands)
              /* Matching address type with a 12bit offset and
                 ADDRESS_LO_SUM.  */
              if (const_arith_operand (offset, Pmode)
-                 || GET_CODE (offset) == LO_SUM)
+                 || GET_CODE (offset) == LO_SUM
+                 || GET_CODE(XEXP (dest, 0)) == REG)
                return "st.w\t%z1,%0";
              else
-               return "stptr.w\t%z1,%0";
+               {
+                 gcc_assert (TARGET_64BIT);
+                 return "stptr.w\t%z1,%0";
+               }
            case 8:
              if (const_arith_operand (offset, Pmode)
                  || GET_CODE (offset) == LO_SUM)
@@ -5165,10 +5169,14 @@ loongarch_output_move (rtx *operands)
              /* Matching address type with a 12bit offset and
                 ADDRESS_LO_SUM.  */
              if (const_arith_operand (offset, Pmode)
-                 || GET_CODE (offset) == LO_SUM)
+                 || GET_CODE (offset) == LO_SUM
+                 || GET_CODE(XEXP (src, 0)) == REG)
                return "ld.w\t%0,%1";
              else
-               return "ldptr.w\t%0,%1";
+               {
+                 gcc_assert (TARGET_64BIT);
+                 return "ldptr.w\t%0,%1";
+               }
            case 8:
              if (const_arith_operand (offset, Pmode)
                  || GET_CODE (offset) == LO_SUM)
-- 
2.34.1

Reply via email to