From a7fe6482214cb17e37b1099b2e0e7b2a6babdc47 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 12 Jul 2018 09:39:33 +0200 Subject: [PATCH] re PR tree-optimization/86492 (store-merging wrong-code) PR tree-optimization/86492 * gimple-ssa-store-merging.c (imm_store_chain_info::coalesce_immediate_stores): Call check_no_overlap even for the merge_overlapping case. Formatting fix. * gcc.c-torture/execute/pr86492.c: New test. From-SVN: r262576 --- gcc/ChangeLog | 7 ++++ gcc/gimple-ssa-store-merging.c | 13 ++++--- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.c-torture/execute/pr86492.c | 34 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr86492.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c36a8a83c26..415aca314b6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-07-12 Jakub Jelinek + + PR tree-optimization/86492 + * gimple-ssa-store-merging.c + (imm_store_chain_info::coalesce_immediate_stores): Call + check_no_overlap even for the merge_overlapping case. Formatting fix. + 2018-07-12 Richard Biener PR middle-end/86479 diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 6d7e0ebe717..0ae45817347 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -2702,7 +2702,12 @@ imm_store_chain_info::coalesce_immediate_stores () { /* Only allow overlapping stores of constants. */ if (info->rhs_code == INTEGER_CST - && merged_store->stores[0]->rhs_code == INTEGER_CST) + && merged_store->stores[0]->rhs_code == INTEGER_CST + && check_no_overlap (m_store_info, i, INTEGER_CST, + MAX (merged_store->last_order, info->order), + MAX (merged_store->start + + merged_store->width, + info->bitpos + info->bitsize))) { merged_store->merge_overlapping (info); goto done; @@ -2732,10 +2737,8 @@ imm_store_chain_info::coalesce_immediate_stores () info->ops_swapped_p = true; } if (check_no_overlap (m_store_info, i, info->rhs_code, - MAX (merged_store->last_order, - info->order), - MAX (merged_store->start - + merged_store->width, + MAX (merged_store->last_order, info->order), + MAX (merged_store->start + merged_store->width, info->bitpos + info->bitsize))) { /* Turn MEM_REF into BIT_INSERT_EXPR for bit-field stores. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d68cccf3d0b..5992e0d56d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-07-12 Jakub Jelinek + + PR tree-optimization/86492 + * gcc.c-torture/execute/pr86492.c: New test. + 2018-07-12 Richard Biener PR c/86453 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr86492.c b/gcc/testsuite/gcc.c-torture/execute/pr86492.c new file mode 100644 index 00000000000..049563d9209 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr86492.c @@ -0,0 +1,34 @@ +/* PR tree-optimization/86492 */ + +union U +{ + unsigned int r; + struct S + { + unsigned int a:12; + unsigned int b:4; + unsigned int c:16; + } f; +}; + +__attribute__((noipa)) unsigned int +foo (unsigned int x) +{ + union U u; + u.r = 0; + u.f.c = x; + u.f.b = 0xe; + return u.r; +} + +int +main () +{ + union U u; + if (__CHAR_BIT__ * __SIZEOF_INT__ != 32 || sizeof (u.r) != sizeof (u.f)) + return 0; + u.r = foo (0x72); + if (u.f.a != 0 || u.f.b != 0xe || u.f.c != 0x72) + __builtin_abort (); + return 0; +} -- 2.30.2