summaryrefslogtreecommitdiff
path: root/gcc/c-gimplify.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2007-10-29 22:26:59 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2007-10-29 22:26:59 +0000
commit75b97c6e174474efa617f823c48b578ae6dae8de (patch)
tree2b6f28406d370623a5e985861bc9536a99083bfa /gcc/c-gimplify.c
parente80ea974b1b54d96090e3a454ac7a74085f1fe2e (diff)
downloadgcc-75b97c6e174474efa617f823c48b578ae6dae8de.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129743 138bc75d-0d04-0410-961f-82ee72b054a4
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;
}