Hi, This patch adds some of the missing patterns in match.pd for ABSU_EXPR and it is a revised version based on the review at https://gcc.gnu.org/ml/gcc-patches/2018-07/msg00046.html Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Is this OK trunk?
Thanks, Kugan gcc/testsuite/ChangeLog: 2018-10-25 Kugan Vivekanandarajah <kugan.vivekanandara...@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. gcc/ChangeLog: 2018-10-25 Kugan Vivekanandarajah <kugan.vivekanandara...@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.
From de3cc3764cc38e4a28fd4edf138e77c310513eba Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org> Date: Wed, 24 Oct 2018 20:43:54 +1100 Subject: [PATCH] absu pattern Change-Id: I1f8fab31a33790f2266683230d38a2172f710f4d --- gcc/doc/generic.texi | 6 ++++++ gcc/match.pd | 24 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/gimplefe-30.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/gimplefe-31.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/gimplefe-32.c | 14 ++++++++++++++ gcc/testsuite/gcc.dg/gimplefe-33.c | 16 ++++++++++++++++ 6 files changed, 92 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-30.c create mode 100644 gcc/testsuite/gcc.dg/gimplefe-31.c create mode 100644 gcc/testsuite/gcc.dg/gimplefe-32.c create mode 100644 gcc/testsuite/gcc.dg/gimplefe-33.c diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi index cf4bcf5..41a4062 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 +eauivalent 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 b36d7cc..1c1f225 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/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" } } */ -- 2.7.4