From 0faf9ab4d6abd4f5b74ec2ca46a59a0c4b85f6a4 Mon Sep 17 00:00:00 2001 From: Will Schmidt Date: Fri, 28 Oct 2016 13:28:46 +0000 Subject: [PATCH] re PR middle-end/72747 (powerpc: wrong code generated for vec_splats in cascading assignment) gcc: 2016-10-26 Will Schmidt PR middle-end/72747 * gimplify.c (gimplify_init_constructor): Move emit of constructor assignment to earlier in the if/else logic. testsuite: 2016-10-26 Will Schmidt PR middle-end/72747 * c-c++-common/pr72747-1.c: New test. * c-c++-common/pr72747-2.c: Likewise. From-SVN: r241647 --- gcc/ChangeLog | 6 ++++++ gcc/gimplify.c | 23 +++++++++++------------ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/c-c++-common/pr72747-1.c | 16 ++++++++++++++++ gcc/testsuite/c-c++-common/pr72747-2.c | 18 ++++++++++++++++++ 5 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr72747-1.c create mode 100644 gcc/testsuite/c-c++-common/pr72747-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 223396ce498..f932103b4c1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-10-28 Will Schmidt + + PR middle-end/72747 + * gimplify.c (gimplify_init_constructor): Move emit of constructor + assignment to earlier in the if/else logic. + 2016-10-28 Richard Biener PR middle-end/78128 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 5da1725acd1..1531582be11 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -4730,24 +4730,23 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, if (ret == GS_ERROR) return GS_ERROR; - else if (want_value) + /* If we have gimplified both sides of the initializer but have + not emitted an assignment, do so now. */ + if (*expr_p) + { + tree lhs = TREE_OPERAND (*expr_p, 0); + tree rhs = TREE_OPERAND (*expr_p, 1); + gassign *init = gimple_build_assign (lhs, rhs); + gimplify_seq_add_stmt (pre_p, init); + } + if (want_value) { *expr_p = object; return GS_OK; } else { - /* If we have gimplified both sides of the initializer but have - not emitted an assignment, do so now. */ - if (*expr_p) - { - tree lhs = TREE_OPERAND (*expr_p, 0); - tree rhs = TREE_OPERAND (*expr_p, 1); - gassign *init = gimple_build_assign (lhs, rhs); - gimplify_seq_add_stmt (pre_p, init); - *expr_p = NULL; - } - + *expr_p = NULL; return GS_ALL_DONE; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a51fcf4d7b5..b4d7ec055c8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-10-26 Will Schmidt + + PR middle-end/72747 + * c-c++-common/pr72747-1.c: New test. + * c-c++-common/pr72747-2.c: Likewise. + 2016-10-28 Andreas Krebbel * gcc.target/s390/oscbreak-1.c: New test. diff --git a/gcc/testsuite/c-c++-common/pr72747-1.c b/gcc/testsuite/c-c++-common/pr72747-1.c new file mode 100644 index 00000000000..e87069df0f6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr72747-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec -fdump-tree-gimple" } */ + +/* PR 72747: Test that cascaded definition is happening for constant vectors. */ + +#include + +int main (int argc, char *argv[]) +{ + __vector int v1,v2; + v1 = v2 = vec_splats ((int) 42); + return 0; +} +/* { dg-final { scan-tree-dump-times " v2 = { 42, 42, 42, 42 }" 1 "gimple" } } */ + diff --git a/gcc/testsuite/c-c++-common/pr72747-2.c b/gcc/testsuite/c-c++-common/pr72747-2.c new file mode 100644 index 00000000000..080d6fc4251 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr72747-2.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-c -maltivec -fdump-tree-gimple" } */ + +/* PR 72747: test that cascaded definition is happening for non constants. */ + +void foo () +{ + extern int i; + __vector int v,w; + v = w = (vector int) { i }; +} + +int main (int argc, char *argv[]) +{ + return 0; +} +/* { dg-final { scan-tree-dump-times " w = {i.0_1}" 1 "gimple" } } */ -- 2.30.2