]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rs6000: MMA test case emits wrong code when building a vector pair [PR102976]
authorPeter Bergner <bergner@linux.ibm.com>
Tue, 16 Nov 2021 18:14:22 +0000 (12:14 -0600)
committerPeter Bergner <bergner@linux.ibm.com>
Sat, 15 Jan 2022 04:54:39 +0000 (22:54 -0600)
PR102976 shows a test case where we generate wrong code when building
a vector pair from 2 vector registers.  The bug here is that with unlucky
register assignments, we can clobber one of the input operands before
we write both registers of the output operand.  The solution is to use
early-clobbers in the assemble pair and accumulator patterns.

2021-11-16  Peter Bergner  <bergner@linux.ibm.com>

gcc/
PR target/102976
* config/rs6000/mma.md (*vsx_assemble_pair): Add early-clobber for
output operand.
(*mma_assemble_acc): Likewise.

gcc/testsuite/
PR target/102976
* gcc.target/powerpc/pr102976.c: New test.

(cherry picked from commit 4cdf7db9a39d18bd536d816a5751d4d3cf23808b)

gcc/config/rs6000/mma.md
gcc/testsuite/gcc.target/powerpc/pr102976.c [new file with mode: 0644]

index c267a4c82e26329088fd932216d9a0f57d573de6..27f64d2cb7c343b90883cc0b7a5859bf4aa962d0 100644 (file)
   DONE;
 })
 
+;; We cannot update the two output registers atomically, so mark the output
+;; as an early clobber so we don't accidentally clobber the input operands.  */
+
 (define_insn_and_split "*vsx_assemble_pair"
-  [(set (match_operand:POI 0 "vsx_register_operand" "=wa")
+  [(set (match_operand:POI 0 "vsx_register_operand" "=&wa")
         (unspec:POI [(match_operand:V16QI 1 "mma_assemble_input_operand" "mwa")
                     (match_operand:V16QI 2 "mma_assemble_input_operand" "mwa")]
                      UNSPEC_VSX_ASSEMBLE))]
   DONE;
 })
 
+;; We cannot update the four output registers atomically, so mark the output
+;; as an early clobber so we don't accidentally clobber the input operands.  */
+
 (define_insn_and_split "*mma_assemble_acc"
-  [(set (match_operand:PXI 0 "fpr_reg_operand" "=d")
+  [(set (match_operand:PXI 0 "fpr_reg_operand" "=&d")
        (unspec:PXI [(match_operand:V16QI 1 "mma_assemble_input_operand" "mwa")
                     (match_operand:V16QI 2 "mma_assemble_input_operand" "mwa")
                     (match_operand:V16QI 3 "mma_assemble_input_operand" "mwa")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr102976.c b/gcc/testsuite/gcc.target/powerpc/pr102976.c
new file mode 100644 (file)
index 0000000..5a4320f
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-require-effective-target power10_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power10" } */
+
+#include <altivec.h>
+void
+bug (__vector_pair *dst)
+{
+  register vector unsigned char vec0 asm ("vs44");
+  register vector unsigned char vec1 asm ("vs32");
+  __builtin_vsx_build_pair (dst, vec0, vec1);
+}
+
+/* { dg-final { scan-assembler-times {(?p)\mxxlor \d+,44,44\M} 1 } } */
+/* { dg-final { scan-assembler-times {(?p)\mxxlor \d+,32,32\M} 1 } } */