]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
m68k: fix adddi3/subdi3 with POST_INC/PRE_DEC destination
authorAndreas Schwab <schwab@linux-m68k.org>
Mon, 29 Sep 2025 16:46:45 +0000 (18:46 +0200)
committerAndreas Schwab <schwab@linux-m68k.org>
Wed, 1 Oct 2025 17:12:06 +0000 (19:12 +0200)
This part has never been exercised until r15-1579-g792f97b44ffc5e.

PR target/122066
* config/m68k/m68k.md (adddi3, subdi3): Strip POST_INC and PRE_DEC
when generating high part of the destination operand.

* gcc.c-torture/compile/pr122066.c: New test.

gcc/config/m68k/m68k.md
gcc/testsuite/gcc.c-torture/compile/pr122066.c [new file with mode: 0644]

index c96937f0b2ca6668d3937554acaeedf44b827726..7f345bfa123bce6d1b9b40a4b6b0cc8c1ca7c6d8 100644 (file)
       gcc_assert (GET_CODE (operands[0]) == MEM);
       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
        {
-         operands[1] = gen_rtx_MEM (SImode,
-                                    plus_constant (Pmode,
-                                                   XEXP(operands[0], 0), -8));
+         operands[1]
+           = gen_rtx_MEM (SImode,
+                          plus_constant (Pmode,
+                                         XEXP (XEXP (operands[0], 0), 0), -8));
          return "move%.l %0,%3\;add%.l %R2,%0\;addx%.l %2,%3\;move%.l %3,%1";
        }
       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
        {
-         operands[1] = XEXP(operands[0], 0);
+         operands[1] = XEXP (XEXP (operands[0], 0), 0);
          return "add%.l %R2,%0\;move%.l %0,%3\;addx%.l %2,%3\;move%.l %3,%1";
        }
       else
       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
        {
          operands[1]
-           = gen_rtx_MEM (SImode, plus_constant (Pmode,
-                                                 XEXP (operands[0], 0), -8));
+           = gen_rtx_MEM (SImode,
+                          plus_constant (Pmode,
+                                         XEXP (XEXP (operands[0], 0), 0), -8));
          return "move%.l %0,%3\;sub%.l %R2,%0\;subx%.l %2,%3\;move%.l %3,%1";
        }
       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
        {
-         operands[1] = XEXP(operands[0], 0);
+         operands[1] = XEXP (XEXP (operands[0], 0), 0);
          return "sub%.l %R2,%0\;move%.l %0,%3\;subx%.l %2,%3\;move%.l %3,%1";
        }
       else
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr122066.c b/gcc/testsuite/gcc.c-torture/compile/pr122066.c
new file mode 100644 (file)
index 0000000..5fecb7f
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR target/122066 -- adddi3/subdi3 mishandle POST_INC/PRE_DEC dest on m68k */
+
+struct {
+  long long wp_ssd[3];
+  long long wp_sum[3];
+} m_lowres;
+void calcAdaptiveQuantFrame() {
+  for (int i = 0; i < 3; i++) {
+    long sum = m_lowres.wp_sum[i];
+    long long ssd = m_lowres.wp_ssd[i];
+    m_lowres.wp_ssd[i] = ssd - sum;
+  }
+  for (int i = 0; i < 3; i++) {
+    long sum = m_lowres.wp_sum[i];
+    long long ssd = m_lowres.wp_ssd[i];
+    m_lowres.wp_ssd[i] = ssd + sum;
+  }
+}