Hi,

Add support for gimple folding of the vec_madd() (vector multiply-add)
intrinsics.
Testcase coverage is provided by the existing tests 
 gcc.target/powerpc/fold-vec-madd-*.c
    
Sniff-tests appear clean.  A full regtest is currently running across assorted 
Power systems. (P6-P9).
OK for trunk (pending clean run results)?
    
Thanks,
-Will
    
[gcc]
    
2017-10-25  Will Schmidt <will_schm...@vnet.ibm.com>

        * config/rs6000/rs6000.c: (rs6000_gimple_fold_builtin) Add support for
          gimple folding of vec_madd() intrinsics.

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 4837e14..04c2b15 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -16606,10 +16606,43 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
                                           build_int_cst (arg2_type, 0)), arg0);
         gimple_set_location (g, loc);
         gsi_replace (gsi, g, true);
         return true;
       }
+
+    /* vec_madd (Float) */
+    case ALTIVEC_BUILTIN_VMADDFP:
+    case VSX_BUILTIN_XVMADDDP:
+      {
+       arg0 = gimple_call_arg (stmt, 0);
+       arg1 = gimple_call_arg (stmt, 1);
+       tree arg2 = gimple_call_arg (stmt, 2);
+       lhs = gimple_call_lhs (stmt);
+       gimple *g = gimple_build_assign (lhs, FMA_EXPR , arg0, arg1, arg2);
+       gimple_set_location (g, gimple_location (stmt));
+       gsi_replace (gsi, g, true);
+       return true;
+      }
+    /* vec_madd (Integral) */
+    case ALTIVEC_BUILTIN_VMLADDUHM:
+      {
+       arg0 = gimple_call_arg (stmt, 0);
+       arg1 = gimple_call_arg (stmt, 1);
+       tree arg2 = gimple_call_arg (stmt, 2);
+       lhs = gimple_call_lhs (stmt);
+       tree lhs_type = TREE_TYPE (lhs);
+       location_t loc = gimple_location (stmt);
+       gimple_seq stmts = NULL;
+       tree mult_result = gimple_build (&stmts, loc, MULT_EXPR,
+                                      lhs_type, arg0, arg1);
+       tree plus_result = gimple_build (&stmts, loc, PLUS_EXPR,
+                                      lhs_type, mult_result, arg2);
+       gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
+       update_call_from_tree (gsi, plus_result);
+       return true;
+      }
+
     default:
        if (TARGET_DEBUG_BUILTIN)
           fprintf (stderr, "gimple builtin intrinsic not matched:%d %s %s\n",
                    fn_code, fn_name1, fn_name2);
       break;


Reply via email to