From a5648717a8826a1bb60afd31b56c48b60d3813d4 Mon Sep 17 00:00:00 2001 From: Will Schmidt Date: Mon, 11 Dec 2017 21:15:48 +0000 Subject: [PATCH] rs6000.c (rs6000_gimple_fold_builtin): Add support for early folding of splat_u{8,16,32}. [gcc] 2017-12-11 Will Schmidt * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for early folding of splat_u{8,16,32}. [testsuite] 2017-12-11 Will Schmidt * gcc.target/powerpc/fold-vec-splat-misc-invalid.c: New. From-SVN: r255549 --- gcc/ChangeLog | 5 +++ gcc/config/rs6000/rs6000.c | 22 +++++++++++++ gcc/testsuite/ChangeLog | 4 +++ .../powerpc/fold-vec-splat-misc-invalid.c | 33 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 gcc/testsuite/gcc.target/powerpc/fold-vec-splat-misc-invalid.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 10ef11cdd47..b1a689feeff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-12-11 Will Schmidt + + * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for + early folding of splat_u{8,16,32}. + 2017-12-11 Jakub Jelinek * config/aarch64/aarch64.c (aarch64_print_operand): Don't start diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 155ea6e9d99..9ed90bfda32 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -16621,6 +16621,28 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) fold_compare_helper (gsi, LE_EXPR, stmt); return true; + /* flavors of vec_splat_[us]{8,16,32}. */ + case ALTIVEC_BUILTIN_VSPLTISB: + case ALTIVEC_BUILTIN_VSPLTISH: + case ALTIVEC_BUILTIN_VSPLTISW: + { + arg0 = gimple_call_arg (stmt, 0); + lhs = gimple_call_lhs (stmt); + /* Only fold the vec_splat_*() if arg0 is constant. */ + if (TREE_CODE (arg0) != INTEGER_CST) + return false; + gimple_seq stmts = NULL; + location_t loc = gimple_location (stmt); + tree splat_value = gimple_convert (&stmts, loc, + TREE_TYPE (TREE_TYPE (lhs)), arg0); + gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); + tree splat_tree = build_vector_from_val (TREE_TYPE (lhs), splat_value); + g = gimple_build_assign (lhs, splat_tree); + gimple_set_location (g, gimple_location (stmt)); + gsi_replace (gsi, g, true); + return true; + } + default: if (TARGET_DEBUG_BUILTIN) fprintf (stderr, "gimple builtin intrinsic not matched:%d %s %s\n", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index acd4578f20e..dced5e7b59c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-12-11 Will Schmidt + + * gcc.target/powerpc/fold-vec-splat-misc-invalid.c: New. + 2017-12-11 Thomas Koenig PR fortran/83379 diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-misc-invalid.c b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-misc-invalid.c new file mode 100644 index 00000000000..20f5b05561e --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-misc-invalid.c @@ -0,0 +1,33 @@ +/* Verify that overloaded built-ins for vec_splat_s8 and vec_splat_s16 + generate errors as expected when we attempt to use invalid inputs. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_vsx_ok } */ +/* { dg-options "-mvsx -O2" } */ + +#include + +vector signed short +testss_1 (unsigned int ui) +{ + return vec_splat_s16 (ui);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector unsigned short +testss_2 (signed int si) +{ + return vec_splat_u16 (si);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector signed char +testsc_1 (unsigned int ui) +{ + return vec_splat_s8 (ui); /* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + +vector unsigned char +testsc_2 (signed int si) +{ + return vec_splat_u8 (si);/* { dg-error "argument 1 must be a 5-bit signed literal" } */ +} + -- 2.30.2