From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7CA8F3858028; Thu, 1 Apr 2021 08:52:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CA8F3858028 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-7946] bswap: Handle bswapping of pointers [PR96573] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: b75c4e1384c021ca94fc8e8db8e517e802b820f3 X-Git-Newrev: 5b9a65ecbeb22ef6dd3344baae97f85b645522e3 Message-Id: <20210401085213.7CA8F3858028@sourceware.org> Date: Thu, 1 Apr 2021 08:52:13 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2021 08:52:13 -0000 https://gcc.gnu.org/g:5b9a65ecbeb22ef6dd3344baae97f85b645522e3 commit r11-7946-g5b9a65ecbeb22ef6dd3344baae97f85b645522e3 Author: Jakub Jelinek Date: Thu Apr 1 10:51:03 2021 +0200 bswap: Handle bswapping of pointers [PR96573] In GCC8/9 we used to optimize this into a bswap, but we no longer do. Handling byteswapping of pointers is easy, all we need is to allow them, for the __builtin_bswap* we already use TYPE_PRECISION to determine the precision and we cast the operand and result to the correct type if they aren't uselessly convertible to what the builtin expects. 2021-04-01 Jakub Jelinek PR tree-optimization/96573 * gimple-ssa-store-merging.c (init_symbolic_number): Handle also pointer types. * gcc.dg/pr96573.c: New test. Diff: --- gcc/gimple-ssa-store-merging.c | 2 +- gcc/testsuite/gcc.dg/pr96573.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 213c1551d39..30bd66335ba 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -333,7 +333,7 @@ init_symbolic_number (struct symbolic_number *n, tree src) { int size; - if (! INTEGRAL_TYPE_P (TREE_TYPE (src))) + if (!INTEGRAL_TYPE_P (TREE_TYPE (src)) && !POINTER_TYPE_P (TREE_TYPE (src))) return false; n->base_addr = n->offset = n->alias_set = n->vuse = NULL_TREE; diff --git a/gcc/testsuite/gcc.dg/pr96573.c b/gcc/testsuite/gcc.dg/pr96573.c new file mode 100644 index 00000000000..3acf117f063 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96573.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/96573 */ +/* { dg-do compile { target { lp64 || ilp32 } } } */ +/* { dg-require-effective-target bswap } */ +/* { dg-options "-O3 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump "__builtin_bswap" "optimized" } } */ + +typedef __SIZE_TYPE__ size_t; + +void * +foo (void * const p) +{ + const size_t m = sizeof (p) - 1; + const unsigned char * const o = (unsigned char*) &p; + void *n; + unsigned char * const q = (unsigned char *) &n; + unsigned char i; + for (i = 0; i <= m; ++i) + q[m - i] = o[i]; + return n; +}