diff options
author | Richard Biener <rguenther@suse.de> | 2024-02-20 11:47:03 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2024-05-07 14:19:35 +0200 |
commit | bed6ec161be8c5ca2f24195900ce3c9b81c3e141 (patch) | |
tree | 7dd43e3a58257f3146d570a8b226fa6b4625eb06 /gcc | |
parent | cc2f3e408ee095653e6658b3126efce717a5586e (diff) | |
download | gcc-bed6ec161be8c5ca2f24195900ce3c9b81c3e141.zip gcc-bed6ec161be8c5ca2f24195900ce3c9b81c3e141.tar.gz gcc-bed6ec161be8c5ca2f24195900ce3c9b81c3e141.tar.bz2 |
middle-end/27800 - avoid unnecessary temporary during gimplification
This avoids a tempoary when gimplifying reg = a ? b : c, re-using
the LHS of an assignment if that's a register.
PR middle-end/27800
* gimplify.cc (gimplify_modify_expr_rhs): For a COND_EXPR
avoid a temporary from gimplify_cond_expr when the LHS is
a register by pushing the assignment into the COND_EXPR arms.
* gcc.dg/pr27800.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/gimplify.cc | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr27800.c | 11 |
2 files changed, 16 insertions, 2 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 7f94f5f..b0ed58e 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -6078,8 +6078,11 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, /* If we're assigning to a non-register type, push the assignment down into the branches. This is mandatory for ADDRESSABLE types, since we cannot generate temporaries for such, but it saves a - copy in other cases as well. */ - if (!is_gimple_reg_type (TREE_TYPE (*from_p))) + copy in other cases as well. + Also avoid an extra temporary and copy when assigning to + a register. */ + if (!is_gimple_reg_type (TREE_TYPE (*from_p)) + || (is_gimple_reg (*to_p) && !gimplify_ctxp->allow_rhs_cond_expr)) { /* This code should mirror the code in gimplify_cond_expr. */ enum tree_code code = TREE_CODE (*expr_p); diff --git a/gcc/testsuite/gcc.dg/pr27800.c b/gcc/testsuite/gcc.dg/pr27800.c new file mode 100644 index 0000000..e92ebc2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr27800.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +int iii (int a, int b, int c) +{ + return a ? b : c; +} + +/* Verify we end up with two assignments and not an extra copy + resulting from another temporary generated from gimplify_cond_expr. */ +/* { dg-final { scan-tree-dump-times " = " 2 "gimple" } } */ |