From aa55dc0ca33c1c22af4aab73d232d0811edca305 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 2 Nov 2016 15:00:48 +0000 Subject: [PATCH] gimple-ssa-store-merging.c: Include gimplify-me.h. 2016-11-02 Richard Biener * gimple-ssa-store-merging.c: Include gimplify-me.h. (imm_store_chain_info::output_merged_stores): Force base_addr to be proper GIMPLE for a MEM_REF address. (pass_store_merging::execute): Restrict negative bitpos handling to non-MEM_REF bases. Remove TREE_THIS_VOLATILE check. Take into account non-NULL_TREE offset if the base is already addressable. * gcc.dg/store_merging_8.c: New testcase. From-SVN: r241796 --- gcc/ChangeLog | 10 +++++++ gcc/gimple-ssa-store-merging.c | 41 ++++++++++++++++++++------ gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/store_merging_8.c | 38 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/store_merging_8.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 76b90a889a5..241ff78d555 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2016-11-02 Richard Biener + + * gimple-ssa-store-merging.c: Include gimplify-me.h. + (imm_store_chain_info::output_merged_stores): Force base_addr + to be proper GIMPLE for a MEM_REF address. + (pass_store_merging::execute): Restrict negative bitpos + handling to non-MEM_REF bases. Remove TREE_THIS_VOLATILE + check. Take into account non-NULL_TREE offset if the base + is already addressable. + 2016-11-26 Wilco Dijkstra * config/aarch64/aarch64-simd.md (aarch64_crypto_sha1hv4si): diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 081620e50f6..1bca4a13758 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -125,6 +125,7 @@ #include "tree-cfg.h" #include "tree-eh.h" #include "target.h" +#include "gimplify-me.h" /* The maximum size (in bits) of the stores this pass should generate. */ #define MAX_STORE_BITSIZE (BITS_PER_WORD) @@ -1127,6 +1128,8 @@ imm_store_chain_info::output_merged_store (merged_store_group *group) unsigned int i; bool fail = false; + tree addr = force_gimple_operand_1 (unshare_expr (base_addr), &seq, + is_gimple_mem_ref_addr, NULL_TREE); FOR_EACH_VEC_ELT (split_stores, i, split_store) { unsigned HOST_WIDE_INT try_size = split_store->size; @@ -1137,7 +1140,7 @@ imm_store_chain_info::output_merged_store (merged_store_group *group) tree int_type = build_nonstandard_integer_type (try_size, UNSIGNED); int_type = build_aligned_type (int_type, align); - tree dest = fold_build2 (MEM_REF, int_type, base_addr, + tree dest = fold_build2 (MEM_REF, int_type, addr, build_int_cst (offset_type, try_pos)); tree src = native_interpret_expr (int_type, @@ -1366,15 +1369,10 @@ pass_store_merging::execute (function *fun) &unsignedp, &reversep, &volatilep); /* As a future enhancement we could handle stores with the same base and offset. */ - bool invalid = offset || reversep || bitpos < 0 + bool invalid = reversep || ((bitsize > MAX_BITSIZE_MODE_ANY_INT) && (TREE_CODE (rhs) != INTEGER_CST)) - || !rhs_valid_for_store_merging_p (rhs) - /* An access may not be volatile itself but base_addr may be - a volatile decl i.e. MEM[&volatile-decl]. The hashing for - tree_operand_hash won't consider such stores equal to each - other so we can't track chains on them. */ - || TREE_THIS_VOLATILE (base_addr); + || !rhs_valid_for_store_merging_p (rhs); /* We do not want to rewrite TARGET_MEM_REFs. */ if (TREE_CODE (base_addr) == TARGET_MEM_REF) @@ -1398,7 +1396,32 @@ pass_store_merging::execute (function *fun) /* get_inner_reference returns the base object, get at its address now. */ else - base_addr = build_fold_addr_expr (base_addr); + { + if (bitpos < 0) + invalid = true; + base_addr = build_fold_addr_expr (base_addr); + } + + if (! invalid + && offset != NULL_TREE) + { + /* If the access is variable offset then a base + decl has to be address-taken to be able to + emit pointer-based stores to it. + ??? We might be able to get away with + re-using the original base up to the first + variable part and then wrapping that inside + a BIT_FIELD_REF. */ + tree base = get_base_address (base_addr); + if (! base + || (DECL_P (base) + && ! TREE_ADDRESSABLE (base))) + invalid = true; + else + base_addr = build2 (POINTER_PLUS_EXPR, + TREE_TYPE (base_addr), + base_addr, offset); + } struct imm_store_chain_info **chain_info = m_stores.get (base_addr); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e475c0e2606..6ca1e69a097 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-11-02 Richard Biener + + * gcc.dg/store_merging_8.c: New testcase. + 2016-11-02 Fritz O. Reese * gfortran.dg/warn_argument_mismatch_1.f90: New test. diff --git a/gcc/testsuite/gcc.dg/store_merging_8.c b/gcc/testsuite/gcc.dg/store_merging_8.c new file mode 100644 index 00000000000..15e80c7d953 --- /dev/null +++ b/gcc/testsuite/gcc.dg/store_merging_8.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target non_strict_align } */ +/* { dg-options "-O2 -fdump-tree-store-merging" } */ + +struct baz { + struct bar { + int a; + char b; + char c; + char d; + char e; + char f; + char g; + } a[4]; +} x; +struct baz *xx = &x; + +void +foo1 (int i) +{ + x.a[i].b = 0; + x.a[i].a = 0; + x.a[i].c = 0; + x.a[i].d = 0; + x.a[i].e = 0; +} + +void +foo2 (int i) +{ + x.a[i].b = 0; + x.a[i].a = 0; + x.a[i].c = 1; + x.a[i].d = 0; + x.a[i].e = 0; +} + +/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } } */ -- 2.30.2