From: Thomas Preud'homme Date: Wed, 28 Jan 2015 10:20:19 +0000 (+0000) Subject: re PR tree-optimization/64718 (Bad 16-bit bswap replacement) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8447859b3ecba626580a9b812a236ecc6438d730;p=gcc.git re PR tree-optimization/64718 (Bad 16-bit bswap replacement) 2015-01-28 Thomas Preud'homme gcc/ PR tree-optimization/64718 * tree-ssa-math-opts.c (pass_optimize_bswap::execute): Make bswap_type be a 16bit unsigned integer when n->range is 16. (bswap_replace): Convert src to that type if necessary for all bswap sizes. Fix rotation right notation in nearby comment. Use bswap_type set in pass_optimize_bswap::execute (). gcc/testsuite/ PR tree-optimization/64718 * gcc.c-torture/execute/pr64718.c: New test. From-SVN: r220203 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b5d0d2d19e6..71413471372 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-01-28 Thomas Preud'homme + + PR tree-optimization/64718 + * tree-ssa-math-opts.c (pass_optimize_bswap::execute): Make bswap_type + be a 16bit unsigned integer when n->range is 16. + (bswap_replace): Convert src to that type if necessary for all bswap + sizes. Fix rotation right notation in nearby comment. Use bswap_type + set in pass_optimize_bswap::execute (). + 2015-01-28 James Greenhalgh * config/aarch64/aarch64-simd.md (aarch64_abs): New. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index efa70174dfb..4f4e72ca9f7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-28 Thomas Preud'homme + + PR tree-optimization/64718 + * gcc.c-torture/execute/pr64718.c: New test. + 2015-01-28 James Greenhalgh * gcc.target/aarch64/abs_2.c: New. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr64718.c b/gcc/testsuite/gcc.c-torture/execute/pr64718.c new file mode 100644 index 00000000000..58773e0453a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr64718.c @@ -0,0 +1,18 @@ +static int __attribute__ ((noinline, noclone)) +swap (int x) +{ + return (unsigned short) ((unsigned short) x << 8 | (unsigned short) x >> 8); +} + +static int a = 0x1234; + +int +main (void) +{ + int b = 0x1234; + if (swap (a) != 0x3412) + __builtin_abort (); + if (swap (b) != 0x3412) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 479f49f3a90..e30116dab1a 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2355,30 +2355,28 @@ bswap_replace (gimple cur_stmt, gimple src_stmt, tree fndecl, tree bswap_type, tmp = src; + /* Convert the src expression if necessary. */ + if (!useless_type_conversion_p (TREE_TYPE (tmp), bswap_type)) + { + gimple convert_stmt; + + tmp = make_temp_ssa_name (bswap_type, NULL, "bswapsrc"); + convert_stmt = gimple_build_assign (tmp, NOP_EXPR, src); + gsi_insert_before (&gsi, convert_stmt, GSI_SAME_STMT); + } + /* Canonical form for 16 bit bswap is a rotate expression. Only 16bit values are considered as rotation of 2N bit values by N bits is generally not - equivalent to a bswap. Consider for instance 0x01020304 >> 16 which gives - 0x03040102 while a bswap for that value is 0x04030201. */ + equivalent to a bswap. Consider for instance 0x01020304 r>> 16 which + gives 0x03040102 while a bswap for that value is 0x04030201. */ if (bswap && n->range == 16) { tree count = build_int_cst (NULL, BITS_PER_UNIT); - bswap_type = TREE_TYPE (src); - src = fold_build2 (LROTATE_EXPR, bswap_type, src, count); + src = fold_build2 (LROTATE_EXPR, bswap_type, tmp, count); bswap_stmt = gimple_build_assign (NULL, src); } else - { - /* Convert the src expression if necessary. */ - if (!useless_type_conversion_p (TREE_TYPE (tmp), bswap_type)) - { - gimple convert_stmt; - tmp = make_temp_ssa_name (bswap_type, NULL, "bswapsrc"); - convert_stmt = gimple_build_assign (tmp, NOP_EXPR, src); - gsi_insert_before (&gsi, convert_stmt, GSI_SAME_STMT); - } - - bswap_stmt = gimple_build_call (fndecl, 1, tmp); - } + bswap_stmt = gimple_build_call (fndecl, 1, tmp); tmp = tgt; @@ -2386,6 +2384,7 @@ bswap_replace (gimple cur_stmt, gimple src_stmt, tree fndecl, tree bswap_type, if (!useless_type_conversion_p (TREE_TYPE (tgt), bswap_type)) { gimple convert_stmt; + tmp = make_temp_ssa_name (bswap_type, NULL, "bswapdst"); convert_stmt = gimple_build_assign (tgt, NOP_EXPR, tmp); gsi_insert_after (&gsi, convert_stmt, GSI_SAME_STMT); @@ -2498,7 +2497,7 @@ pass_optimize_bswap::execute (function *fun) /* Already in canonical form, nothing to do. */ if (code == LROTATE_EXPR || code == RROTATE_EXPR) continue; - load_type = uint16_type_node; + load_type = bswap_type = uint16_type_node; break; case 32: load_type = uint32_type_node;