summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-27 14:59:04 +0000
committeramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-27 14:59:04 +0000
commit641ae1b81aab5bb902a382fbfc1695a7be2624e3 (patch)
treed967b316fe6af130249a30a38dff681ae741f5f9
parent52cbeb376bc7420f99245a6d6c7891d6e366aa24 (diff)
downloadgcc-641ae1b81aab5bb902a382fbfc1695a7be2624e3.tar.gz
* match.pd ((convert (op:s (convert@2 @0) (convert?@3 @1)))): Add
support for constant operand for OP. gcc/testsuite * gcc.dg/fold-narrowbopcst-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241624 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd14
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/fold-narrowbopcst-1.c14
4 files changed, 32 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9eea9a3b7a3..73d3004b7cd 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-27 Bin Cheng <bin.cheng@arm.com>
+
+ * match.pd ((convert (op:s (convert@2 @0) (convert?@3 @1)))): Add
+ support for constant operand for OP.
+
2016-10-27 Jakub Jelinek <jakub@redhat.com>
* dwarf2out.c (gen_member_die): Only reparent_child instead of
diff --git a/gcc/match.pd b/gcc/match.pd
index 73bee34dcc5..48f73514a3f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3277,7 +3277,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
operation and convert the result to the desired type. */
(for op (plus minus)
(simplify
- (convert (op:s (convert@2 @0) (convert@3 @1)))
+ (convert (op:s (convert@2 @0) (convert?@3 @1)))
(if (INTEGRAL_TYPE_P (type)
/* We check for type compatibility between @0 and @1 below,
so there's no need to check that @1/@3 are integral types. */
@@ -3293,12 +3293,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
/* The inner conversion must be a widening conversion. */
&& TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
- && types_match (@0, @1)
- && types_match (@0, type))
+ && types_match (@0, type)
+ && (types_match (@0, @1)
+ /* Or the second operand is const integer or converted const
+ integer from valueize. */
+ || TREE_CODE (@1) == INTEGER_CST))
(if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
- (convert (op @0 @1))
+ (op @0 (convert @1))
(with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
- (convert (op (convert:utype @0) (convert:utype @1))))))))
+ (convert (op (convert:utype @0)
+ (convert:utype @1))))))))
/* This is another case of narrowing, specifically when there's an outer
BIT_AND_EXPR which masks off bits outside the type of the innermost
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 22a9ce83ac3..72f669cfcf7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-10-27 Bin Cheng <bin.cheng@arm.com>
+
+ * gcc.dg/fold-narrowbopcst-1.c: New test.
+
2016-10-27 Fritz Reese <fritzoreese@gmail.com>
* gfortran.dg/dec_io_5.f90: Don't use "test.txt", and use
diff --git a/gcc/testsuite/gcc.dg/fold-narrowbopcst-1.c b/gcc/testsuite/gcc.dg/fold-narrowbopcst-1.c
new file mode 100644
index 00000000000..8a33677c274
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-narrowbopcst-1.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int foo1 (unsigned char a[], unsigned int x)
+{
+ unsigned int i;
+ for (i = 0; i < 1000; i++)
+ {
+ x = a[i];
+ a[i] = (unsigned char)(x >= 100 ? x - 100 : 0);
+ }
+ return x;
+}
+/* { dg-final { scan-tree-dump " = _.* \\+ 156" "optimized" } } */