aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2015-10-19 13:58:27 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2015-10-19 13:58:27 +0000
commit4534c2032ba23be0a1f6b74ea2e23bc94df0cb81 (patch)
treeab6e2c78aa78e165e6c5f5307a23b2f3a4fa5fff /gcc
parent1c6e3c3e2ce560e555ba7d75a22179757a3c6489 (diff)
downloadgcc-4534c2032ba23be0a1f6b74ea2e23bc94df0cb81.zip
gcc-4534c2032ba23be0a1f6b74ea2e23bc94df0cb81.tar.gz
gcc-4534c2032ba23be0a1f6b74ea2e23bc94df0cb81.tar.bz2
gimple-fold.c (gimple_phi_nonnegative_warnv_p): New function.
2015-10-19 Richard Biener <rguenther@suse.de> * gimple-fold.c (gimple_phi_nonnegative_warnv_p): New function. (gimple_stmt_nonnegative_warnv_p): Use it. * match.pd (CPROJ): New operator list. (cproj (complex ...)): Move simplifications from ... * builtins.c (fold_builtin_cproj): ... here. * gcc.dg/torture/builtin-cproj-1.c: Skip for -O0. From-SVN: r228970
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/builtins.c27
-rw-r--r--gcc/gimple-fold.c21
-rw-r--r--gcc/match.pd27
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/torture/builtin-cproj-1.c1
6 files changed, 61 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b04f38b..ed0f4ce 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2015-10-19 Richard Biener <rguenther@suse.de>
+
+ * gimple-fold.c (gimple_phi_nonnegative_warnv_p): New function.
+ (gimple_stmt_nonnegative_warnv_p): Use it.
+ * match.pd (CPROJ): New operator list.
+ (cproj (complex ...)): Move simplifications from ...
+ * builtins.c (fold_builtin_cproj): ... here.
+
2015-10-19 H.J. Lu <hongjiu.lu@intel.com>
* config/i386/i386.c (ix86_expand_vector_move): Use
diff --git a/gcc/builtins.c b/gcc/builtins.c
index b4ac535..50ed7c6 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7657,33 +7657,6 @@ fold_builtin_cproj (location_t loc, tree arg, tree type)
else
return arg;
}
- else if (TREE_CODE (arg) == COMPLEX_EXPR)
- {
- tree real = TREE_OPERAND (arg, 0);
- tree imag = TREE_OPERAND (arg, 1);
-
- STRIP_NOPS (real);
- STRIP_NOPS (imag);
-
- /* If the real part is inf and the imag part is known to be
- nonnegative, return (inf + 0i). Remember side-effects are
- possible in the imag part. */
- if (TREE_CODE (real) == REAL_CST
- && real_isinf (TREE_REAL_CST_PTR (real))
- && tree_expr_nonnegative_p (imag))
- return omit_one_operand_loc (loc, type,
- build_complex_cproj (type, false),
- arg);
-
- /* If the imag part is inf, return (inf+I*copysign(0,imag)).
- Remember side-effects are possible in the real part. */
- if (TREE_CODE (imag) == REAL_CST
- && real_isinf (TREE_REAL_CST_PTR (imag)))
- return
- omit_one_operand_loc (loc, type,
- build_complex_cproj (type, TREE_REAL_CST_PTR
- (imag)->sign), arg);
- }
return NULL_TREE;
}
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 2e5942a..85ff018 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -6224,6 +6224,24 @@ gimple_call_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
strict_overflow_p, depth);
}
+/* Return true if return value of call STMT is known to be non-negative.
+ If the return value is based on the assumption that signed overflow is
+ undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
+ *STRICT_OVERFLOW_P. DEPTH is the current nesting depth of the query. */
+
+static bool
+gimple_phi_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
+ int depth)
+{
+ for (unsigned i = 0; i < gimple_phi_num_args (stmt); ++i)
+ {
+ tree arg = gimple_phi_arg_def (stmt, i);
+ if (!tree_single_nonnegative_warnv_p (arg, strict_overflow_p, depth + 1))
+ return false;
+ }
+ return true;
+}
+
/* Return true if STMT is known to compute a non-negative value.
If the return value is based on the assumption that signed overflow is
undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
@@ -6241,6 +6259,9 @@ gimple_stmt_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
case GIMPLE_CALL:
return gimple_call_nonnegative_warnv_p (stmt, strict_overflow_p,
depth);
+ case GIMPLE_PHI:
+ return gimple_phi_nonnegative_warnv_p (stmt, strict_overflow_p,
+ depth);
default:
return false;
}
diff --git a/gcc/match.pd b/gcc/match.pd
index f3813d8..98f4b2c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see
(define_operator_list TAN BUILT_IN_TANF BUILT_IN_TAN BUILT_IN_TANL)
(define_operator_list COSH BUILT_IN_COSHF BUILT_IN_COSH BUILT_IN_COSHL)
(define_operator_list CEXPI BUILT_IN_CEXPIF BUILT_IN_CEXPI BUILT_IN_CEXPIL)
+(define_operator_list CPROJ BUILT_IN_CPROJF BUILT_IN_CPROJ BUILT_IN_CPROJL)
/* Simplifications of operations with one constant operand and
simplifications to constants or single values. */
@@ -2361,6 +2362,32 @@ along with GCC; see the file COPYING3. If not see
(cbrts (pows tree_expr_nonnegative_p@0 @1))
(pows @0 (mult @1 { build_real_truncate (type, dconst_third ()); })))))
+/* If the real part is inf and the imag part is known to be
+ nonnegative, return (inf + 0i). */
+(simplify
+ (CPROJ (complex REAL_CST@0 tree_expr_nonnegative_p@1))
+ (if (real_isinf (TREE_REAL_CST_PTR (@0)))
+ (with
+ {
+ REAL_VALUE_TYPE rinf;
+ real_inf (&rinf);
+ }
+ { build_complex (type, build_real (TREE_TYPE (type), rinf),
+ build_zero_cst (TREE_TYPE (type))); })))
+/* If the imag part is inf, return (inf+I*copysign(0,imag)). */
+(simplify
+ (CPROJ (complex @0 REAL_CST@1))
+ (if (real_isinf (TREE_REAL_CST_PTR (@1)))
+ (with
+ {
+ REAL_VALUE_TYPE rinf, rzero = dconst0;
+ real_inf (&rinf);
+ rzero.sign = TREE_REAL_CST_PTR (@1)->sign;
+ }
+ { build_complex (type, build_real (TREE_TYPE (type), rinf),
+ build_real (TREE_TYPE (type), rzero)); })))
+
+
/* Narrowing of arithmetic and logical operations.
These are conceptually similar to the transformations performed for
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a717cca..a5c3aa6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2015-10-19 Richard Biener <rguenther@suse.de>
+
+ * gcc.dg/torture/builtin-cproj-1.c: Skip for -O0.
+
2015-10-19 H.J. Lu <hongjiu.lu@intel.com>
PR target/67995
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-cproj-1.c b/gcc/testsuite/gcc.dg/torture/builtin-cproj-1.c
index 53ae604..9aa6691 100644
--- a/gcc/testsuite/gcc.dg/torture/builtin-cproj-1.c
+++ b/gcc/testsuite/gcc.dg/torture/builtin-cproj-1.c
@@ -6,6 +6,7 @@
Origin: Kaveh R. Ghazi, April 9, 2010. */
/* { dg-do link } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
/* { dg-add-options ieee } */
/* All references to link_error should go away at compile-time. The