From 0f78434635f6e78cae50408a8bb76c35658551d4 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 6 Apr 2017 12:31:05 +0000 Subject: [PATCH] re PR middle-end/80262 (address space gets lost in memory access) 2017-04-06 Richard Biener PR tree-optimization/80262 * tree-sra.c (build_ref_for_offset): Preserve address-space information. * tree-ssa-sccvn.c (vn_reference_maybe_forwprop_address): Drop useless address-space information on MEM_REF offsets. * gcc.target/i386/pr80262.c: New testcase. From-SVN: r246728 --- gcc/ChangeLog | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/i386/pr80262.c | 26 +++++++++++++++++++++++++ gcc/tree-sra.c | 7 +++++++ gcc/tree-ssa-sccvn.c | 4 ++-- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr80262.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3d13b55101a..020d9f8707d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-04-06 Richard Biener + + PR tree-optimization/80262 + * tree-sra.c (build_ref_for_offset): Preserve address-space + information. + * tree-ssa-sccvn.c (vn_reference_maybe_forwprop_address): + Drop useless address-space information on MEM_REF offsets. + 2017-04-05 Andreas Schwab * builtins.def (BUILT_IN_UPDATE_SETJMP_BUF): Fix type. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0517d3fa437..db72e9adf61 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-06 Richard Biener + + PR tree-optimization/80262 + * gcc.target/i386/pr80262.c: New testcase. + 2017-04-06 Richard Biener PR middle-end/80281 diff --git a/gcc/testsuite/gcc.target/i386/pr80262.c b/gcc/testsuite/gcc.target/i386/pr80262.c new file mode 100644 index 00000000000..f34d06e8c8a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr80262.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef struct { + int v; +} S1; +S1 clearS1 () { S1 s1 = { 0 }; return s1; } + +typedef struct { + S1 s1[4]; +} S2; +void clearS2 (__seg_gs S2* p, int n) { + for (int i = 0; i < n; ++i) + p->s1[i] = clearS1 (); +} + +typedef struct { + int pad; + S2 s2; +} S3; + +long int BASE; + +void fn1(int n) { + clearS2 (&(((__seg_gs S3*)(BASE))->s2), n); +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 02453d3ed9a..31834ed7af7 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -1638,6 +1638,13 @@ build_ref_for_offset (location_t loc, tree base, HOST_WIDE_INT offset, unsigned HOST_WIDE_INT misalign; unsigned int align; + /* Preserve address-space information. */ + addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (base)); + if (as != TYPE_ADDR_SPACE (exp_type)) + exp_type = build_qualified_type (exp_type, + TYPE_QUALS (exp_type) + | ENCODE_QUAL_ADDR_SPACE (as)); + gcc_checking_assert (offset % BITS_PER_UNIT == 0); get_object_alignment_1 (base, &align, &misalign); base = get_addr_base_and_unit_offset (base, &base_offset); diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index e7502de790d..bce247a1489 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1233,8 +1233,8 @@ vn_reference_maybe_forwprop_address (vec *ops, && tem[tem.length () - 2].opcode == MEM_REF) { vn_reference_op_t new_mem_op = &tem[tem.length () - 2]; - new_mem_op->op0 = fold_convert (TREE_TYPE (mem_op->op0), - new_mem_op->op0); + new_mem_op->op0 = wide_int_to_tree (TREE_TYPE (mem_op->op0), + new_mem_op->op0); } else gcc_assert (tem.last ().opcode == STRING_CST); -- 2.30.2