From 9a9822e13ece30035ad18fed7f3946d8b1ce67a9 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 23 May 2011 12:03:19 +0000 Subject: [PATCH] re PR tree-optimization/15419 (memcpy pessimization) 2011-05-23 Richard Guenther PR middle-end/15419 * builtins.c (fold_builtin_memory_op): Be less restrictive about what pointer types we accept for folding. * gcc.dg/memcpy-3.c: New testcase. From-SVN: r174065 --- gcc/ChangeLog | 6 ++++++ gcc/builtins.c | 18 +++++++----------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/memcpy-3.c | 13 +++++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/memcpy-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 253ce2ac7ee..25b569eefa4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-05-23 Richard Guenther + + PR middle-end/15419 + * builtins.c (fold_builtin_memory_op): Be less restrictive about + what pointer types we accept for folding. + 2011-05-23 Rainer Orth * gthr-gnat.c: Remove. diff --git a/gcc/builtins.c b/gcc/builtins.c index bd61f29a616..a23237dd94a 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -8509,6 +8509,9 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src, Perhaps we ought to inherit type from non-VOID argument here? */ STRIP_NOPS (src); STRIP_NOPS (dest); + if (!POINTER_TYPE_P (TREE_TYPE (src)) + || !POINTER_TYPE_P (TREE_TYPE (dest))) + return NULL_TREE; /* As we fold (void *)(p + CST) to (void *)p + CST undo this here. */ if (TREE_CODE (src) == POINTER_PLUS_EXPR) { @@ -8525,8 +8528,7 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src, dest = build1 (NOP_EXPR, TREE_TYPE (tem), dest); } srctype = TREE_TYPE (TREE_TYPE (src)); - if (srctype - && TREE_CODE (srctype) == ARRAY_TYPE + if (TREE_CODE (srctype) == ARRAY_TYPE && !tree_int_cst_equal (TYPE_SIZE_UNIT (srctype), len)) { srctype = TREE_TYPE (srctype); @@ -8534,21 +8536,15 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src, src = build1 (NOP_EXPR, build_pointer_type (srctype), src); } desttype = TREE_TYPE (TREE_TYPE (dest)); - if (desttype - && TREE_CODE (desttype) == ARRAY_TYPE + if (TREE_CODE (desttype) == ARRAY_TYPE && !tree_int_cst_equal (TYPE_SIZE_UNIT (desttype), len)) { desttype = TREE_TYPE (desttype); STRIP_NOPS (dest); dest = build1 (NOP_EXPR, build_pointer_type (desttype), dest); } - if (!srctype || !desttype - || TREE_ADDRESSABLE (srctype) - || TREE_ADDRESSABLE (desttype) - || !TYPE_SIZE_UNIT (srctype) - || !TYPE_SIZE_UNIT (desttype) - || TREE_CODE (TYPE_SIZE_UNIT (srctype)) != INTEGER_CST - || TREE_CODE (TYPE_SIZE_UNIT (desttype)) != INTEGER_CST) + if (TREE_ADDRESSABLE (srctype) + || TREE_ADDRESSABLE (desttype)) return NULL_TREE; src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2429b60bf24..c41d32448bb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-05-23 Richard Guenther + + PR middle-end/15419 + * gcc.dg/memcpy-3.c: New testcase. + 2011-05-23 Jakub Jelinek PR middle-end/48973 diff --git a/gcc/testsuite/gcc.dg/memcpy-3.c b/gcc/testsuite/gcc.dg/memcpy-3.c new file mode 100644 index 00000000000..ba3db56c99d --- /dev/null +++ b/gcc/testsuite/gcc.dg/memcpy-3.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +int get_int(const void *p) +{ + int w; + __builtin_memcpy(&w, p, sizeof (int)); + return w; +} + +/* { dg-final { scan-tree-dump-not "memcpy" "optimized" } } */ +/* { dg-final { scan-tree-dump-times "MEM" 1 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ -- 2.30.2