arc: Fix cached to uncached moves.
authorClaudiu Zissulescu <claziss@synopsys.com>
Tue, 29 Dec 2020 11:30:04 +0000 (13:30 +0200)
committerClaudiu Zissulescu <claziss@synopsys.com>
Tue, 29 Dec 2020 11:41:03 +0000 (13:41 +0200)
We need an temporary register when moving data from a cached memory to
an uncached memory. Fix this issue and add a test for it.

gcc/
2020-12-29  Claudiu Zissulescu  <claziss@synopsys.com>

* config/arc/arc.c (prepare_move_operands): Use a temporary
registers when we have cached mem-to-uncached mem moves.

gcc/testsuite/
2020-12-29  Vladimir Isaev  <isaev@synopsys.com>

* gcc.target/arc/uncached-9.c: New test.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
gcc/config/arc/arc.c
gcc/testsuite/gcc.target/arc/uncached-9.c [new file with mode: 0644]

index 6a9e1fb..d0a52ee 100644 (file)
@@ -9234,13 +9234,21 @@ prepare_move_operands (rtx *operands, machine_mode mode)
        }
       if (arc_is_uncached_mem_p (operands[1]))
        {
+         rtx tmp = operands[0];
+
          if (MEM_P (operands[0]))
-           operands[0] = force_reg (mode, operands[0]);
+           tmp = gen_reg_rtx (mode);
+
          emit_insn (gen_rtx_SET
-                    (operands[0],
+                    (tmp,
                      gen_rtx_UNSPEC_VOLATILE
                      (mode, gen_rtvec (1, operands[1]),
                       VUNSPEC_ARC_LDDI)));
+         if (MEM_P (operands[0]))
+           {
+             operands[1] = tmp;
+             return false;
+           }
          return true;
        }
     }
diff --git a/gcc/testsuite/gcc.target/arc/uncached-9.c b/gcc/testsuite/gcc.target/arc/uncached-9.c
new file mode 100644 (file)
index 0000000..4caba29
--- /dev/null
@@ -0,0 +1,39 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include <stdlib.h>
+
+struct uncached_st
+{
+  int value;
+} __attribute__((uncached));
+
+struct cached_st
+{
+  int value;
+};
+
+struct uncached_st g_uncached_st =
+  {
+    .value = 17
+  };
+
+struct cached_st g_cached_st =
+  {
+    .value = 4
+  };
+
+void __attribute__((noinline)) test_struct_copy (void)
+{
+  g_cached_st.value = g_uncached_st.value;
+}
+
+int main (void)
+{
+  test_struct_copy();
+
+  if (g_cached_st.value != g_uncached_st.value)
+    abort ();
+
+  return 0;
+}