]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rs6000: Add support for compatibility built-ins
authorPeter Bergner <bergner@linux.ibm.com>
Tue, 23 Feb 2021 23:16:10 +0000 (17:16 -0600)
committerPeter Bergner <bergner@linux.ibm.com>
Tue, 23 Feb 2021 23:16:10 +0000 (17:16 -0600)
The LLVM and GCC teams agreed to rename the __builtin_mma_assemble_pair and
__builtin_mma_disassemble_pair built-ins to __builtin_vsx_assemble_pair and
__builtin_vsx_disassemble_pair respectively.  It's too late to remove the
old names, so this patch renames the built-ins to the new names and then
adds support for creating compatibility built-ins (ie, multiple built-in
functions generate the same code) and then creates compatibility built-ins
using the old names.

2021-02-23  Peter Bergner  <bergner@linux.ibm.com>

gcc/
* config/rs6000/mma.md (mma_assemble_pair): Rename from this...
(vsx_assemble_pair): ...to this.
(*mma_assemble_pair): Rename from this...
(*vsx_assemble_pair): ...to this.
(mma_disassemble_pair): Rename from this...
(vsx_disassemble_pair): ...to this.
(*mma_disassemble_pair): Rename from this...
(*vsx_disassemble_pair): ...to this.
* config/rs6000/rs6000-builtin.def (BU_MMA_V2, BU_MMA_V3,
BU_COMPAT): New macros.
(mma_assemble_pair): Rename from this...
(vsx_assemble_pair): ...to this.
(mma_disassemble_pair): Rename from this...
(vsx_disassemble_pair): ...to this.
(mma_assemble_pair): New compatibility built-in.
(mma_disassemble_pair): Likewise.
* config/rs6000/rs6000-call.c (struct builtin_compatibility): New.
(RS6000_BUILTIN_COMPAT): Define.
(bdesc_compat): New.
(mma_expand_builtin): Use VSX_BUILTIN_DISASSEMBLE_PAIR_INTERNAL.
(rs6000_gimple_fold_mma_builtin): Use MMA_BUILTIN_DISASSEMBLE_PAIR
and VSX_BUILTIN_ASSEMBLE_PAIR.
(rs6000_init_builtins): Register compatibility built-ins.
(mma_init_builtins): Use VSX_BUILTIN_ASSEMBLE_PAIR,
VSX_BUILTIN_ASSEMBLE_PAIR_INTERNAL, VSX_BUILTIN_DISASSEMBLE_PAIR and
VSX_BUILTIN_DISASSEMBLE_PAIR_INTERNAL.
* doc/extend.texi (__builtin_mma_assemble_pair): Rename from this...
(__builtin_vsx_assemble_pair): ...to this.
(__builtin_mma_disassemble_pair): Rename from this...
(__builtin_vsx_disassemble_pair): ...to this.

gcc/testsuite/
* gcc.target/powerpc/mma-builtin-4.c: Add tests for
__builtin_vsx_assemble_pair and __builtin_vsx_disassemble_pair.
Add __has_builtin tests for built-ins.
Update expected instruction counts.

gcc/config/rs6000/mma.md
gcc/config/rs6000/rs6000-builtin.def
gcc/config/rs6000/rs6000-call.c
gcc/doc/extend.texi
gcc/testsuite/gcc.target/powerpc/mma-builtin-4.c

index 87569f1c31dfb556a47fffc7824a4fa3f97e538e..c40501f2e091f4ca748ad0bc3788b1ea18c67251 100644 (file)
    (set_attr "length" "*,*,16")
    (set_attr "max_prefixed_insns" "2,2,*")])
 
-(define_expand "mma_assemble_pair"
+(define_expand "vsx_assemble_pair"
   [(match_operand:OO 0 "vsx_register_operand")
    (match_operand:V16QI 1 "mma_assemble_input_operand")
    (match_operand:V16QI 2 "mma_assemble_input_operand")]
   DONE;
 })
 
-(define_insn_and_split "*mma_assemble_pair"
+(define_insn_and_split "*vsx_assemble_pair"
   [(set (match_operand:OO 0 "vsx_register_operand" "=wa")
        (unspec:OO [(match_operand:V16QI 1 "mma_assemble_input_operand" "mwa")
                    (match_operand:V16QI 2 "mma_assemble_input_operand" "mwa")]
   DONE;
 })
 
-(define_expand "mma_disassemble_pair"
+(define_expand "vsx_disassemble_pair"
   [(match_operand:V16QI 0 "mma_disassemble_output_operand")
    (match_operand:OO 1 "vsx_register_operand")
    (match_operand 2 "const_0_to_1_operand")]
   DONE;
 })
 
-(define_insn_and_split "*mma_disassemble_pair"
+(define_insn_and_split "*vsx_disassemble_pair"
   [(set (match_operand:V16QI 0 "mma_disassemble_output_operand" "=mwa")
        (unspec:V16QI [(match_operand:OO 1 "vsx_register_operand" "wa")
                      (match_operand 2 "const_0_to_1_operand")]
index 058a32abf4ce9584884a336aa3bf6f8fba9e0f8e..609bebdfd74850692f80acc7a7efbddb2610796f 100644 (file)
        ATTR    builtin attribute information.
        ICODE   Insn code of the function that implements the builtin.  */
 
+#ifndef RS6000_BUILTIN_COMPAT
+  #undef BU_COMPAT
+  #define BU_COMPAT(ENUM, COMPAT_NAME)
+
 #ifndef RS6000_BUILTIN_0
   #error "RS6000_BUILTIN_0 is not defined."
 #endif
   #error "RS6000_BUILTIN_X is not defined."
 #endif
 
+#else
+  /* Compatibility builtins.  These builtins are simply mapped into
+     their compatible builtin function identified by ENUM.  */
+  #undef BU_COMPAT
+  #define BU_COMPAT(ENUM, COMPAT_NAME) { ENUM, "__builtin_" COMPAT_NAME },
+
+  #undef RS6000_BUILTIN_0
+  #undef RS6000_BUILTIN_1
+  #undef RS6000_BUILTIN_2
+  #undef RS6000_BUILTIN_3
+  #undef RS6000_BUILTIN_4
+  #undef RS6000_BUILTIN_A
+  #undef RS6000_BUILTIN_D
+  #undef RS6000_BUILTIN_H
+  #undef RS6000_BUILTIN_M
+  #undef RS6000_BUILTIN_P
+  #undef RS6000_BUILTIN_X
+  #define RS6000_BUILTIN_0(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_4(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_M(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
+  #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
+#endif
+
 #ifndef BU_AV_1
 /* Define convenience macros using token pasting to allow fitting everything in
    one line.  */
                     | RS6000_BTC_BINARY),                              \
                    CODE_FOR_ ## ICODE)                 /* ICODE */
 
+/* Like BU_MMA_2, but uses "vsx" rather than "mma" naming.  */
+#define BU_MMA_V2(ENUM, NAME, ATTR, ICODE)                             \
+  RS6000_BUILTIN_M (VSX_BUILTIN_ ## ENUM,              /* ENUM */      \
+                   "__builtin_vsx_" NAME,              /* NAME */      \
+                   RS6000_BTM_MMA,                     /* MASK */      \
+                   (RS6000_BTC_ ## ATTR                /* ATTR */      \
+                    | RS6000_BTC_BINARY                                \
+                    | RS6000_BTC_VOID                                  \
+                    | RS6000_BTC_GIMPLE),                              \
+                   CODE_FOR_nothing)                   /* ICODE */     \
+  RS6000_BUILTIN_M (VSX_BUILTIN_ ## ENUM ## _INTERNAL, /* ENUM */      \
+                   "__builtin_vsx_" NAME "_internal",  /* NAME */      \
+                   RS6000_BTM_MMA,                     /* MASK */      \
+                   (RS6000_BTC_ ## ATTR                /* ATTR */      \
+                    | RS6000_BTC_BINARY),                              \
+                   CODE_FOR_ ## ICODE)                 /* ICODE */
+
 #define BU_MMA_3(ENUM, NAME, ATTR, ICODE)                              \
   RS6000_BUILTIN_M (MMA_BUILTIN_ ## ENUM,              /* ENUM */      \
                    "__builtin_mma_" NAME,              /* NAME */      \
                     | RS6000_BTC_TERNARY),                             \
                    CODE_FOR_ ## ICODE)                 /* ICODE */
 
+/* Like BU_MMA_3, but uses "vsx" rather than "mma" naming.  */
+#define BU_MMA_V3(ENUM, NAME, ATTR, ICODE)                             \
+  RS6000_BUILTIN_M (VSX_BUILTIN_ ## ENUM,              /* ENUM */      \
+                   "__builtin_vsx_" NAME,              /* NAME */      \
+                   RS6000_BTM_MMA,                     /* MASK */      \
+                   (RS6000_BTC_ ## ATTR                /* ATTR */      \
+                    | RS6000_BTC_TERNARY                               \
+                    | RS6000_BTC_VOID                                  \
+                    | RS6000_BTC_GIMPLE),                              \
+                   CODE_FOR_nothing)                   /* ICODE */     \
+  RS6000_BUILTIN_M (VSX_BUILTIN_ ## ENUM ## _INTERNAL, /* ENUM */      \
+                   "__builtin_vsx_" NAME "_internal",  /* NAME */      \
+                   RS6000_BTM_MMA,                     /* MASK */      \
+                   (RS6000_BTC_ ## ATTR                /* ATTR */      \
+                    | RS6000_BTC_TERNARY),                             \
+                   CODE_FOR_ ## ICODE)                 /* ICODE */
+
 #define BU_MMA_5(ENUM, NAME, ATTR, ICODE)                              \
   RS6000_BUILTIN_M (MMA_BUILTIN_ ## ENUM,              /* ENUM */      \
                    "__builtin_mma_" NAME,              /* NAME */      \
@@ -3136,9 +3204,11 @@ BU_MMA_1 (XXMTACC,           "xxmtacc",          QUAD, mma_xxmtacc)
 BU_MMA_1 (XXSETACCZ,       "xxsetaccz",        MISC, mma_xxsetaccz)
 
 BU_MMA_2 (DISASSEMBLE_ACC, "disassemble_acc",  QUAD, mma_disassemble_acc)
-BU_MMA_2 (DISASSEMBLE_PAIR,"disassemble_pair", PAIR, mma_disassemble_pair)
+BU_MMA_V2 (DISASSEMBLE_PAIR, "disassemble_pair", PAIR, vsx_disassemble_pair)
+BU_COMPAT (VSX_BUILTIN_DISASSEMBLE_PAIR, "mma_disassemble_pair")
 
-BU_MMA_3 (ASSEMBLE_PAIR,    "assemble_pair",   MISC, mma_assemble_pair)
+BU_MMA_V3 (ASSEMBLE_PAIR,   "assemble_pair",   MISC, vsx_assemble_pair)
+BU_COMPAT (VSX_BUILTIN_ASSEMBLE_PAIR, "mma_assemble_pair")
 BU_MMA_3 (XVBF16GER2,      "xvbf16ger2",       MISC, mma_xvbf16ger2)
 BU_MMA_3 (XVF16GER2,       "xvf16ger2",        MISC, mma_xvf16ger2)
 BU_MMA_3 (XVF32GER,        "xvf32ger",         MISC, mma_xvf32ger)
index de0ce50796d750be7264ea5ee0497821dc7621ae..d2bd03e7a62f8551d0a0c8f3a361930c3b072ffe 100644 (file)
 #define TARGET_NO_PROTOTYPE 0
 #endif
 
+struct builtin_compatibility
+{
+  const enum rs6000_builtins code;
+  const char *const name;
+};
+
 struct builtin_description
 {
   const HOST_WIDE_INT mask;
@@ -8839,6 +8845,13 @@ def_builtin (const char *name, tree type, enum rs6000_builtins code)
             (int)code, name, attr_string);
 }
 
+static const struct builtin_compatibility bdesc_compat[] =
+{
+#define RS6000_BUILTIN_COMPAT
+#include "rs6000-builtin.def"
+};
+#undef RS6000_BUILTIN_COMPAT
+
 /* Simple ternary operations: VECd = foo (VECa, VECb, VECc).  */
 
 #undef RS6000_BUILTIN_0
@@ -10115,7 +10128,7 @@ mma_expand_builtin (tree exp, rtx target, bool *expandedp)
 
   unsigned attr_args = attr & RS6000_BTC_OPND_MASK;
   if (attr & RS6000_BTC_QUAD
-      || fcode == MMA_BUILTIN_DISASSEMBLE_PAIR_INTERNAL)
+      || fcode == VSX_BUILTIN_DISASSEMBLE_PAIR_INTERNAL)
     attr_args++;
 
   gcc_assert (nopnds == attr_args);
@@ -11730,7 +11743,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi)
   tree new_decl;
 
   if (fncode == MMA_BUILTIN_DISASSEMBLE_ACC
-      || fncode == MMA_BUILTIN_DISASSEMBLE_PAIR)
+      || fncode == VSX_BUILTIN_DISASSEMBLE_PAIR)
     {
       /* This is an MMA disassemble built-in function.  */
       push_gimplify_context (true);
@@ -11745,7 +11758,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi)
         another accumulator/pair, then just copy the entire thing as is.  */
       if ((fncode == MMA_BUILTIN_DISASSEMBLE_ACC
           && TREE_TYPE (TREE_TYPE (dst_ptr)) == vector_quad_type_node)
-         || (fncode == MMA_BUILTIN_DISASSEMBLE_PAIR
+         || (fncode == VSX_BUILTIN_DISASSEMBLE_PAIR
              && TREE_TYPE (TREE_TYPE (dst_ptr)) == vector_pair_type_node))
        {
          tree dst = build_simple_mem_ref (build1 (VIEW_CONVERT_EXPR,
@@ -11847,7 +11860,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi)
       gcc_unreachable ();
     }
 
-  if (fncode == MMA_BUILTIN_ASSEMBLE_PAIR)
+  if (fncode == VSX_BUILTIN_ASSEMBLE_PAIR)
     lhs = make_ssa_name (vector_pair_type_node);
   else
     lhs = make_ssa_name (vector_quad_type_node);
@@ -13447,6 +13460,18 @@ rs6000_init_builtins (void)
 #ifdef SUBTARGET_INIT_BUILTINS
   SUBTARGET_INIT_BUILTINS;
 #endif
+
+  /* Register the compatibility builtins after all of the normal
+     builtins have been defined.  */
+  const struct builtin_compatibility *d = bdesc_compat;
+  unsigned i;
+  for (i = 0; i < ARRAY_SIZE (bdesc_compat); i++, d++)
+    {
+      tree decl = rs6000_builtin_decls[(int)d->code];
+      gcc_assert (decl != NULL);
+      add_builtin_function (d->name, TREE_TYPE (decl), (int)d->code,
+                           BUILT_IN_MD, NULL, NULL_TREE);
+    }
 }
 
 /* Returns the rs6000 builtin decl for CODE.  */
@@ -14119,7 +14144,7 @@ mma_init_builtins (void)
       else
        {
          if (!(d->code == MMA_BUILTIN_DISASSEMBLE_ACC_INTERNAL
-                || d->code == MMA_BUILTIN_DISASSEMBLE_PAIR_INTERNAL)
+                || d->code == VSX_BUILTIN_DISASSEMBLE_PAIR_INTERNAL)
               && (attr & RS6000_BTC_QUAD) == 0)
            attr_args--;
 
@@ -14129,7 +14154,7 @@ mma_init_builtins (void)
 
       /* This is a disassemble pair/acc function. */
       if (d->code == MMA_BUILTIN_DISASSEMBLE_ACC
-         || d->code == MMA_BUILTIN_DISASSEMBLE_PAIR)
+         || d->code == VSX_BUILTIN_DISASSEMBLE_PAIR)
        {
          op[nopnds++] = build_pointer_type (void_type_node);
          if (d->code == MMA_BUILTIN_DISASSEMBLE_ACC)
@@ -14143,7 +14168,7 @@ mma_init_builtins (void)
          unsigned j = 0;
          if (attr & RS6000_BTC_QUAD
              && d->code != MMA_BUILTIN_DISASSEMBLE_ACC_INTERNAL
-             && d->code != MMA_BUILTIN_DISASSEMBLE_PAIR_INTERNAL)
+             && d->code != VSX_BUILTIN_DISASSEMBLE_PAIR_INTERNAL)
            j = 1;
          for (; j < (unsigned) insn_data[icode].n_operands; j++)
            {
@@ -14151,7 +14176,7 @@ mma_init_builtins (void)
              if (gimple_func && mode == XOmode)
                op[nopnds++] = build_pointer_type (vector_quad_type_node);
              else if (gimple_func && mode == OOmode
-                      && d->code == MMA_BUILTIN_ASSEMBLE_PAIR)
+                      && d->code == VSX_BUILTIN_ASSEMBLE_PAIR)
                op[nopnds++] = build_pointer_type (vector_pair_type_node);
              else
                /* MMA uses unsigned types.  */
index 8bbb93724a93b42c3f13a164f11b4f7e4007d33a..02578cd953fa0867718c0d580b6baffc89aac705 100644 (file)
@@ -22219,8 +22219,8 @@ void __builtin_mma_xxsetaccz (__vector_quad *);
 void __builtin_mma_assemble_acc (__vector_quad *, vec_t, vec_t, vec_t, vec_t);
 void __builtin_mma_disassemble_acc (void *, __vector_quad *);
 
-void __builtin_mma_assemble_pair (__vector_pair *, vec_t, vec_t);
-void __builtin_mma_disassemble_pair (void *, __vector_pair *);
+void __builtin_vsx_assemble_pair (__vector_pair *, vec_t, vec_t);
+void __builtin_vsx_disassemble_pair (void *, __vector_pair *);
 
 vec_t __builtin_vsx_xvcvspbf16 (vec_t);
 vec_t __builtin_vsx_xvcvbf16spn (vec_t);
index f3a857bb8c13844531e1b2c4939b83a445643bc8..3bedf531de010d181d30c4ed35f55b7da6e7f443 100644 (file)
@@ -12,6 +12,14 @@ foo (__vector_pair *dst, vec_t *src)
   *dst = pair;
 }
 
+void
+foo2 (__vector_pair *dst, vec_t *src)
+{
+  __vector_pair pair;
+  __builtin_vsx_assemble_pair (&pair, src[0], src[4]);
+  *dst = pair;
+}
+
 void
 bar (vec_t *dst, __vector_pair *src)
 {
@@ -21,8 +29,33 @@ bar (vec_t *dst, __vector_pair *src)
   dst[4] = res[1];
 }
 
-/* { dg-final { scan-assembler-times {\mlxv\M} 2 } } */
-/* { dg-final { scan-assembler-times {\mlxvp\M} 1 } } */
-/* { dg-final { scan-assembler-times {\mstxv\M} 2 } } */
-/* { dg-final { scan-assembler-times {\mstxvp\M} 1 } } */
+void
+bar2 (vec_t *dst, __vector_pair *src)
+{
+  vec_t res[2];
+  __builtin_vsx_disassemble_pair (res, src);
+  dst[0] = res[0];
+  dst[4] = res[1];
+}
+
+#if !__has_builtin (__builtin_vsx_assemble_pair)
+#  error "__has_builtin (__builtin_vsx_assemble_pair) failed"
+#endif
+
+#if !__has_builtin (__builtin_vsx_disassemble_pair)
+#  error "__has_builtin (__builtin_vsx_disassemble_pair) failed"
+#endif
+
+#if !__has_builtin (__builtin_mma_assemble_pair)
+#  error "__has_builtin (__builtin_mma_assemble_pair) failed"
+#endif
+
+#if !__has_builtin (__builtin_mma_disassemble_pair)
+#  error "__has_builtin (__builtin_mma_disassemble_pair) failed"
+#endif
+
+/* { dg-final { scan-assembler-times {\mlxv\M} 4 } } */
+/* { dg-final { scan-assembler-times {\mlxvp\M} 2 } } */
+/* { dg-final { scan-assembler-times {\mstxv\M} 4 } } */
+/* { dg-final { scan-assembler-times {\mstxvp\M} 2 } } */