summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthopre01 <thopre01@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-28 10:20:19 +0000
committerthopre01 <thopre01@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-28 10:20:19 +0000
commit904c73a0fa6902e4c4bfe1422f67c5f9445c30f7 (patch)
tree79c23d259d3122536e27807b8eb8ee4dcdd18bb3
parent260d579bfd5550f6f48e118ef745bcf19cd5bcb5 (diff)
downloadgcc-904c73a0fa6902e4c4bfe1422f67c5f9445c30f7.tar.gz
2015-01-28 Thomas Preud'homme <thomas.preudhomme@arm.com>
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220203 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr64718.c18
-rw-r--r--gcc/tree-ssa-math-opts.c33
4 files changed, 48 insertions, 17 deletions
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 <thomas.preudhomme@arm.com>
+
+ 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 <james.greenhalgh@arm.com>
* config/aarch64/aarch64-simd.md (aarch64_abs<mode>): 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 <thomas.preudhomme@arm.com>
+
+ PR tree-optimization/64718
+ * gcc.c-torture/execute/pr64718.c: New test.
+
2015-01-28 James Greenhalgh <james.greenhalgh@arm.com>
* 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;