From 0f507a365777b403cf058ee1208bf41a7363a728 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 9 Jan 2020 10:29:54 +0000 Subject: [PATCH] re PR tree-optimization/93040 (gcc doesn't optimize unaligned accesses to a 16-bit value on the x86 as well as it does a 32-bit value (or clang)) 2020-01-09 Richard Biener PR tree-optimization/93040 * gimple-ssa-store-merging.c (find_bswap_or_nop): Raise search limit. * gcc.dg/optimize-bswaphi-1.c: Amend. * gcc.dg/optimize-bswapsi-2.c: Likewise. From-SVN: r280034 --- gcc/ChangeLog | 5 +++++ gcc/gimple-ssa-store-merging.c | 4 ++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/optimize-bswaphi-1.c | 8 +++++++- gcc/testsuite/gcc.dg/optimize-bswapsi-2.c | 13 ++++++++++++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4a8e897a421..dbac2a41cfa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2020-01-09 Richard Biener + + PR tree-optimization/93040 + * gimple-ssa-store-merging.c (find_bswap_or_nop): Raise search limit. + 2020-01-09 Georg-Johann Lay * common/config/avr/avr-common.c (avr_option_optimization_table) diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 0d7639c9dca..741b1ec039c 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -848,11 +848,11 @@ find_bswap_or_nop (gimple *stmt, struct symbolic_number *n, bool *bswap) { /* The last parameter determines the depth search limit. It usually correlates directly to the number n of bytes to be touched. We - increase that number by log2(n) + 1 here in order to also + increase that number by 2 * (log2(n) + 1) here in order to also cover signed -> unsigned conversions of the src operand as can be seen in libgcc, and for initial shift/and operation of the src operand. */ int limit = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (gimple_expr_type (stmt))); - limit += 1 + (int) ceil_log2 ((unsigned HOST_WIDE_INT) limit); + limit += 2 * (1 + (int) ceil_log2 ((unsigned HOST_WIDE_INT) limit)); gimple *ins_stmt = find_bswap_or_nop_1 (stmt, n, limit); if (!ins_stmt) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b4e4f83f4e7..0e18082a829 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-01-09 Richard Biener + + PR tree-optimization/93040 + * gcc.dg/optimize-bswaphi-1.c: Amend. + * gcc.dg/optimize-bswapsi-2.c: Likewise. + 2020-01-09 Jakub Jelinek PR inline-asm/93202 diff --git a/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c b/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c index dcd3c2872d6..e9338d67872 100644 --- a/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c +++ b/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c @@ -54,5 +54,11 @@ swap16 (HItype in) | (((in >> 8) & 0xFF) << 0); } -/* { dg-final { scan-tree-dump-times "16 bit load in target endianness found at" 3 "bswap" } } */ +unsigned short +get_unaligned_16 (unsigned char *p) +{ + return p[0] | (p[1] << 8); +} + +/* { dg-final { scan-tree-dump-times "16 bit load in target endianness found at" 4 "bswap" } } */ /* { dg-final { scan-tree-dump-times "16 bit bswap implementation found at" 4 "bswap" } } */ diff --git a/gcc/testsuite/gcc.dg/optimize-bswapsi-2.c b/gcc/testsuite/gcc.dg/optimize-bswapsi-2.c index 30e677bd947..f111553e1cf 100644 --- a/gcc/testsuite/gcc.dg/optimize-bswapsi-2.c +++ b/gcc/testsuite/gcc.dg/optimize-bswapsi-2.c @@ -44,5 +44,16 @@ uint32_t read_be32_3 (unsigned char *data) | (*data << 24); } -/* { dg-final { scan-tree-dump-times "32 bit load in target endianness found at" 3 "bswap" } } */ +static inline unsigned short +get_unaligned_16 (unsigned char *p) +{ + return p[0] | (p[1] << 8); +} +unsigned int +get_unaligned_32 (unsigned char *p) +{ + return get_unaligned_16 (p) | (get_unaligned_16 (p + 2) << 16); +} + +/* { dg-final { scan-tree-dump-times "32 bit load in target endianness found at" 4 "bswap" } } */ /* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 3 "bswap" } } */ -- 2.30.2