From 1567db2f02e005b7a3349aedf0afb37c36260beb Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 21 Oct 2015 23:12:05 +0200 Subject: [PATCH] fold-const.c (operand_equal_p): Add code matching empty constructors. * fold-const.c (operand_equal_p): Add code matching empty constructors. * gcc.dg/tree-ssa/operand-equal-1.c: Verify that empty constructors are matched. From-SVN: r229147 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 5 +++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/tree-ssa/operand-equal-1.c | 8 ++++++++ 4 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/operand-equal-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 457c3385f87..38ae32110db 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-10-11 Jan Hubicka + + * fold-const.c (operand_equal_p): Add code matching empty + constructors. + 2015-10-21 Eric Botcazou * tree.def (CEIL_DIV_EXPR, FLOOR_DIV_EXPR, ROUND_DIV_EXPR): Tweak diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b7874a08c0b..602ea240cb4 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2891,6 +2891,11 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), flags | OEP_ADDRESS_OF | OEP_CONSTANT_ADDRESS_OF); + case CONSTRUCTOR: + /* In GIMPLE empty constructors are allowed in initializers of + aggregates. */ + return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0)) + && !vec_safe_length (CONSTRUCTOR_ELTS (arg1))); default: break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9c76295c916..4637ae747e2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-10-11 Jan Hubicka + + * gcc.dg/tree-ssa/operand-equal-1.c: Verify that empty constructors + are matched. + 2015-10-21 Richard Sandiford * gcc.dg/lto/20110201-1_0.c: Restrict to sqrt_insn targets. @@ -21,6 +26,7 @@ 2015-10-21 Marek Polacek + PR c/68024 * gcc.dg/pr68024.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/operand-equal-1.c b/gcc/testsuite/gcc.dg/tree-ssa/operand-equal-1.c new file mode 100644 index 00000000000..09e9302ac16 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/operand-equal-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-pre" } */ +struct a {int a,b;}; +struct a ret(int val) +{ + return val? (struct a){} : (struct a){}; +} +/* { dg-final { scan-tree-dump-not "if " "pre"} } */ -- 2.30.2