summaryrefslogtreecommitdiff
path: root/gcc/c-gimplify.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-10-29 23:26:59 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2007-10-29 23:26:59 +0100
commit489f2598af821da1157ec21cd484fcb32a5193e9 (patch)
tree2b6f28406d370623a5e985861bc9536a99083bfa /gcc/c-gimplify.c
parent9f1da821e6de1d5068d8c03cd46d1b05aab799f1 (diff)
downloadgcc-489f2598af821da1157ec21cd484fcb32a5193e9.tar.gz
re PR tree-optimization/33723 (Inefficient code with compound literals)
PR tree-optimization/33723 * c-gimplify.c (c_gimplify_expr): Optimize INIT_EXPR or MODIFY_EXPR with non-addressable COMPOUND_LITERAL_EXPR as source. * gcc.c-torture/execute/20071029-1.c: New test. * gcc.dg/tree-ssa/pr33723.c: New test. From-SVN: r129743
Diffstat (limited to 'gcc/c-gimplify.c')
-rw-r--r--gcc/c-gimplify.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/c-gimplify.c b/gcc/c-gimplify.c
index 9721b67008b..a1ee27bfb70 100644
--- a/gcc/c-gimplify.c
+++ b/gcc/c-gimplify.c
@@ -233,6 +233,29 @@ c_gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p ATTRIBUTE_UNUSED)
case COMPOUND_LITERAL_EXPR:
return gimplify_compound_literal_expr (expr_p, pre_p);
+ case INIT_EXPR:
+ case MODIFY_EXPR:
+ if (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == COMPOUND_LITERAL_EXPR)
+ {
+ tree complit = TREE_OPERAND (*expr_p, 1);
+ tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (complit);
+ tree decl = DECL_EXPR_DECL (decl_s);
+ tree init = DECL_INITIAL (decl);
+
+ /* struct T x = (struct T) { 0, 1, 2 } can be optimized
+ into struct T x = { 0, 1, 2 } if the address of the
+ compound literal has never been taken. */
+ if (!TREE_ADDRESSABLE (complit)
+ && !TREE_ADDRESSABLE (decl)
+ && init)
+ {
+ *expr_p = copy_node (*expr_p);
+ TREE_OPERAND (*expr_p, 1) = init;
+ return GS_OK;
+ }
+ }
+ return GS_UNHANDLED;
+
default:
return GS_UNHANDLED;
}