diff options
author | Richard Biener <rguenther@suse.de> | 2014-07-25 07:44:57 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2014-07-25 07:44:57 +0000 |
commit | b2505143369334866ed98d69f08033068b24de34 (patch) | |
tree | c7fe34fd006f2ff66fbe4a743da4b4b825b9c156 /gcc/testsuite | |
parent | 1ed85d52ef443e528bfccc64d81a7b263e9defa3 (diff) | |
download | gcc-b2505143369334866ed98d69f08033068b24de34.zip gcc-b2505143369334866ed98d69f08033068b24de34.tar.gz gcc-b2505143369334866ed98d69f08033068b24de34.tar.bz2 |
re PR middle-end/61762 (failure to optimize memcpy from constant string)
2014-07-25 Richard Biener <rguenther@suse.de>
PR middle-end/61762
PR middle-end/61894
* fold-const.c (native_encode_int): Add and handle offset
parameter to do partial encodings of expr.
(native_encode_fixed): Likewise.
(native_encode_real): Likewise.
(native_encode_complex): Likewise.
(native_encode_vector): Likewise.
(native_encode_string): Likewise.
(native_encode_expr): Likewise.
* fold-const.c (native_encode_expr): Add offset parameter
defaulting to -1.
* gimple-fold.c (fold_string_cst_ctor_reference): Remove.
(fold_ctor_reference): Handle all reads from tcc_constant
ctors.
* gcc.dg/pr61762.c: New testcase.
* gcc.dg/fold-cstring.c: Likewise.
* gcc.dg/fold-cvect.c: Likewise.
From-SVN: r213045
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-cstring.c | 44 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-cvect.c | 38 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr61762.c | 19 |
4 files changed, 109 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 17daa07..72ba8a7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2014-07-25 Richard Biener <rguenther@suse.de> + + PR middle-end/61762 + PR middle-end/61894 + * gcc.dg/pr61762.c: New testcase. + * gcc.dg/fold-cstring.c: Likewise. + * gcc.dg/fold-cvect.c: Likewise. + 2014-07-24 Ulrich Weigand <Ulrich.Weigand@de.ibm.com> * gcc.target/powerpc/ppc64-abi-warn-3.c: New test. diff --git a/gcc/testsuite/gcc.dg/fold-cstring.c b/gcc/testsuite/gcc.dg/fold-cstring.c new file mode 100644 index 0000000..f92b120 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-cstring.c @@ -0,0 +1,44 @@ +/* { dg-do run } */ +/* { dg-options "-O" } */ + +/* The following are testcases for native_interpret_int, + native_interpret_complex and native_interpret_vector decoding + pieces of a string constant encoded by native_encode_string. */ + +extern void abort (void); + +/* We should fold all reads from xconstant and eliminate it, removing + the reference to blah which cannot be resolved at link time. */ +extern int blah; + +static const struct { + int *y; + const char x[32] __attribute__((aligned(32))); +} xconstant = { &blah, "01234567899876543210123456789000" }; + +typedef int v4si __attribute__((vector_size(16))); + +int main() +{ + if (sizeof (int) != 4) + return 0; + if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + { + if (*(int *)&xconstant.x[4] != 0x34353637) + abort (); + if ((*(v4si *)&xconstant.x[16])[1] != 0x31323334) + abort (); + if (__imag (*(_Complex int *)&xconstant.x[8]) != 0x37363534) + abort (); + } + else if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + { + if (*(int *)&xconstant.x[4] != 0x37363534) + abort (); + if ((*(v4si *)&xconstant.x[16])[1] != 0x34333231) + abort (); + if (__imag (*(_Complex int *)&xconstant.x[8]) != 0x34353637) + abort (); + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/fold-cvect.c b/gcc/testsuite/gcc.dg/fold-cvect.c new file mode 100644 index 0000000..8687f8d --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-cvect.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-options "-O" } */ + +extern void abort (void); + +/* We should fold all reads from xconstant and eliminate it, removing + the reference to blah which cannot be resolved at link time. */ +extern int blah; + +typedef int v4si __attribute__((vector_size(16))); + +static const struct { + int *y; + const v4si x[2] __attribute__((aligned(32))); +} xconstant = { &blah, { { 0, 1, 2, 3 }, { 2, 3, 4, 5 } } }; + +int main() +{ + if (sizeof (int) != 4) + return 0; + if (*(int *)&xconstant.x[0][0] != 0) + abort (); + if (*(int *)&xconstant.x[0][1] != 1) + abort (); + if (*(int *)&xconstant.x[0][2] != 2) + abort (); + if (*(int *)&xconstant.x[0][3] != 3) + abort (); + if (*(int *)&xconstant.x[1][0] != 2) + abort (); + if (*(int *)&xconstant.x[1][1] != 3) + abort (); + if (*(int *)&xconstant.x[1][2] != 4) + abort (); + if (*(int *)&xconstant.x[1][3] != 5) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr61762.c b/gcc/testsuite/gcc.dg/pr61762.c new file mode 100644 index 0000000..5abe534 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr61762.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-release_ssa" } */ + +unsigned int f() +{ + static const char string[] = "Private"; + + unsigned int priv; + __builtin_memcpy(&priv, &string[0], sizeof(priv)); + return priv; +} + +/* We should have removed the static string and simplified the + memcpy to a store from an integer constant. CCP + already performs the simplification but only after release_ssa + the unused local static is removed. */ + +/* { dg-final { scan-tree-dump-not "Private" "release_ssa" } } */ +/* { dg-final { cleanup-tree-dump "release_ssa" } } */ |