aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/doc/generic.texi6
-rw-r--r--gcc/match.pd24
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/gimplefe-30.c16
-rw-r--r--gcc/testsuite/gcc.dg/gimplefe-31.c16
-rw-r--r--gcc/testsuite/gcc.dg/gimplefe-32.c14
-rw-r--r--gcc/testsuite/gcc.dg/gimplefe-33.c16
8 files changed, 107 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4ac333a..e1b641f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2018-10-28 Kugan Vivekanandarajah <kuganv@linaro.org>
+
+ * doc/generic.texi (ABSU_EXPR): Document.
+ * match.pd (absu(x)*absu(x) -> x*x): Handle.
+ (absu(absu(X)) -> absu(X)): Likewise.
+ (absu(-X) -> absu(X)): Likewise.
+ (absu(X) where X is nonnegative -> X): Likewise.
+
2018-10-28 Iain Buclaw <ibuclaw@gdcproject.org>
* Makefile.in (tm_d_file_list, tm_d_include_list): New variables.
diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
index cf4bcf5..5d0a541 100644
--- a/gcc/doc/generic.texi
+++ b/gcc/doc/generic.texi
@@ -1274,6 +1274,7 @@ the byte offset of the field, but should not be used directly; call
@subsection Unary and Binary Expressions
@tindex NEGATE_EXPR
@tindex ABS_EXPR
+@tindex ABSU_EXPR
@tindex BIT_NOT_EXPR
@tindex TRUTH_NOT_EXPR
@tindex PREDECREMENT_EXPR
@@ -1371,6 +1372,11 @@ or complex abs of a complex value, use the @code{BUILT_IN_CABS},
to implement the C99 @code{cabs}, @code{cabsf} and @code{cabsl}
built-in functions.
+@item ABSU_EXPR
+These nodes represent the absolute value of the single operand in
+equivalent unsigned type such that @code{ABSU_EXPR} of TYPE_MIN is
+well defined.
+
@item BIT_NOT_EXPR
These nodes represent bitwise complement, and will always have integral
type. The only operand is the value to be complemented.
diff --git a/gcc/match.pd b/gcc/match.pd
index 8796a40..d07ceb7 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -590,6 +590,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(mult (abs@1 @0) @1)
(mult @0 @0))
+/* Convert absu(x)*absu(x) -> x*x. */
+(simplify
+ (mult (absu@1 @0) @1)
+ (mult (convert@2 @0) @2))
+
/* cos(copysign(x, y)) -> cos(x). Similarly for cosh. */
(for coss (COS COSH)
copysigns (COPYSIGN)
@@ -1121,16 +1126,35 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& tree_nop_conversion_p (type, TREE_TYPE (@2)))
(bit_xor (convert @1) (convert @2))))
+/* Convert abs (abs (X)) into abs (X).
+ also absu (absu (X)) into absu (X). */
(simplify
(abs (abs@1 @0))
@1)
+
+(simplify
+ (absu (convert@2 (absu@1 @0)))
+ (if (tree_nop_conversion_p (TREE_TYPE (@2), TREE_TYPE (@1)))
+ @1))
+
+/* Convert abs[u] (-X) -> abs[u] (X). */
(simplify
(abs (negate @0))
(abs @0))
+
+(simplify
+ (absu (negate @0))
+ (absu @0))
+
+/* Convert abs[u] (X) where X is nonnegative -> (X). */
(simplify
(abs tree_expr_nonnegative_p@0)
@0)
+(simplify
+ (absu tree_expr_nonnegative_p@0)
+ (convert @0))
+
/* A few cases of fold-const.c negate_expr_p predicate. */
(match negate_expr_p
INTEGER_CST
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e49edfb..40ea5a7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2018-10-28 Kugan Vivekanandarajah <kuganv@linaro.org>
+
+ * gcc.dg/gimplefe-30.c: New test.
+ * gcc.dg/gimplefe-31.c: New test.
+ * gcc.dg/gimplefe-32.c: New test.
+ * gcc.dg/gimplefe-33.c: New test.
+
2018-10-28 Iain Buclaw <ibuclaw@gdcproject.org>
* gcc.misc-tests/help.exp: Add D to option descriptions check.
diff --git a/gcc/testsuite/gcc.dg/gimplefe-30.c b/gcc/testsuite/gcc.dg/gimplefe-30.c
new file mode 100644
index 0000000..6c25106
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-30.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fgimple -fdump-tree-optimized" } */
+
+unsigned int __GIMPLE() f(int a)
+{
+ unsigned int t0;
+ unsigned int t1;
+ unsigned int t2;
+ t0 = __ABSU a;
+ t1 = __ABSU a;
+ t2 = t0 * t1;
+ return t2;
+}
+
+
+/* { dg-final { scan-tree-dump-times "ABSU" 0 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/gimplefe-31.c b/gcc/testsuite/gcc.dg/gimplefe-31.c
new file mode 100644
index 0000000..a97d0dd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-31.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fgimple -fdump-tree-optimized" } */
+
+
+unsigned int __GIMPLE() f(int a)
+{
+ unsigned int t0;
+ int t1;
+ unsigned int t2;
+ t0 = __ABSU a;
+ t1 = (int) t0;
+ t2 = __ABSU t1;
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump-times "ABSU" 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/gimplefe-32.c b/gcc/testsuite/gcc.dg/gimplefe-32.c
new file mode 100644
index 0000000..9b3963c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-32.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fgimple -fdump-tree-optimized" } */
+
+unsigned int __GIMPLE() f(int a)
+{
+ int t0;
+ unsigned int t1;
+ t0 = -a;
+ t1 = __ABSU a;
+ return t1;
+}
+
+
+/* { dg-final { scan-tree-dump-times "= -" 0 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/gimplefe-33.c b/gcc/testsuite/gcc.dg/gimplefe-33.c
new file mode 100644
index 0000000..4e49822
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-33.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fgimple -fdump-tree-optimized" } */
+
+int __GIMPLE() f(int c)
+{
+ int D;
+ int _1;
+ unsigned int _2;
+ _1 = __ABS c;
+ _2 = __ABSU _1;
+ D = (int) _2;
+ return D;
+}
+
+
+/* { dg-final { scan-tree-dump-times "ABSU" 0 "optimized" } } */