diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-03-05 08:00:04 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-03-05 08:00:04 +0100 |
commit | fe19699ae2883b252d30f98481d32dabff00744b (patch) | |
tree | 156e2e7833a639349d5dd27e30c93c0f60b8ab49 | |
parent | cb2409c60aeff498064346f85165531a3bbead14 (diff) |
sccvn: Fix handling of POINTER_PLUS_EXPR in memset offset [PR93582]
> > where POINTER_PLUS_EXPR last operand has sizetype type, thus unsigned,
> > and in the testcase gimple_assign_rhs2 (def) is thus 0xf000000000000001ULL
> > which multiplied by 8 doesn't fit into signed HWI. If it would be treated
> > as signed offset instead, it would fit (-0xfffffffffffffffLL, multiplied
> > by 8 is -0x7ffffffffffffff8LL). Unfortunately with the poly_int obfuscation
> > I'm not sure how to convert it from unsigned to signed poly_int.
>
> mem_ref_offset provides a boiler-plate for this:
>
> poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)), SIGNED);
Thanks, that seems to work.
The test now works on both big-endian and little-endian.
2020-03-05 Richard Biener <rguenther@suse.de>
Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/93582
* tree-ssa-sccvn.c (vn_reference_lookup_3): Treat POINTER_PLUS_EXPR
last operand as signed when looking for memset offset. Formatting
fix.
* gcc.dg/tree-ssa/pr93582-11.c: New test.
Co-authored-by: Richard Biener <rguenther@suse.de>
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr93582-11.c | 16 | ||||
-rw-r--r-- | gcc/tree-ssa-sccvn.c | 12 |
4 files changed, 37 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5b2e4a83721..897c5986e8d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2020-03-05 Richard Biener <rguenther@suse.de> + Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/93582 + * tree-ssa-sccvn.c (vn_reference_lookup_3): Treat POINTER_PLUS_EXPR + last operand as signed when looking for memset offset. Formatting + fix. + 2020-03-04 Andrew Pinski <apinski@marvell.com> PR bootstrap/93962 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 95c8710800b..d4e7a3ac690 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-05 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/93582 + * gcc.dg/tree-ssa/pr93582-11.c: New test. + 2020-03-04 Martin Sebor <msebor@redhat.com> PR c++/90938 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr93582-11.c b/gcc/testsuite/gcc.dg/tree-ssa/pr93582-11.c new file mode 100644 index 00000000000..9ff400eff1d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr93582-11.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/93582 */ +/* { dg-do compile { target lp64 } } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ +/* { dg-final { scan-tree-dump "return 9223372036854775806;" "fre1" } } */ + +union U { struct A { unsigned long long a : 1, b : 62, c : 1; } a; unsigned long long i; }; + +unsigned long long +foo (char *p) +{ + __builtin_memset (p - 0xfffffffffffffffULL, 0, 0xffffffffffffffeULL); + __builtin_memset (p + 1, 0, 0xffffffffffffffeULL); + union U *q = (union U *) (void *) (p - 4); + q->a.b = -1; + return q->i; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 9ea30ef433c..b7174cd603f 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2656,7 +2656,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, { poly_int64 soff; if (TREE_CODE (base) != MEM_REF - || !(mem_ref_offset (base) << LOG2_BITS_PER_UNIT).to_shwi (&soff)) + || !(mem_ref_offset (base) + << LOG2_BITS_PER_UNIT).to_shwi (&soff)) return (void *)-1; offset += soff; offset2 = 0; @@ -2666,10 +2667,13 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, if (is_gimple_assign (def) && gimple_assign_rhs_code (def) == POINTER_PLUS_EXPR && gimple_assign_rhs1 (def) == TREE_OPERAND (base, 0) - && poly_int_tree_p (gimple_assign_rhs2 (def)) - && (wi::to_poly_offset (gimple_assign_rhs2 (def)) - << LOG2_BITS_PER_UNIT).to_shwi (&offset2)) + && poly_int_tree_p (gimple_assign_rhs2 (def))) { + tree rhs2 = gimple_assign_rhs2 (def); + if (!(poly_offset_int::from (wi::to_poly_wide (rhs2), + SIGNED) + << LOG2_BITS_PER_UNIT).to_shwi (&offset2)) + return (void *)-1; ref2 = gimple_assign_rhs1 (def); if (TREE_CODE (ref2) == SSA_NAME) ref2 = SSA_VAL (ref2); |