summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c11
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/fold-div-2.c13
4 files changed, 33 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 630bebc1bbf..b4ff1f89445 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2005-11-21 Uros Bizjak <uros@kss-loka.si>
+
+ * fold-const.c (fold_binary) <RDIV_EXPR>: Optimize A / A to 1.0
+ if we don't care about NaNs or Infinities.
+
2005-11-20 Ian Lance Taylor <ian@airs.com>
PR rtl-optimization/24883
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c4dd4f955a7..e7f550b2038 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8227,6 +8227,17 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& real_zerop (arg1))
return NULL_TREE;
+ /* Optimize A / A to 1.0 if we don't care about
+ NaNs or Infinities. */
+ if (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
+ && ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0)))
+ && operand_equal_p (arg0, arg1, 0))
+ {
+ tree r = build_real (TREE_TYPE (arg0), dconst1);
+
+ return omit_two_operands (type, r, arg0, arg1);
+ }
+
/* (-A) / (-B) -> A / B */
if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
return fold_build2 (RDIV_EXPR, type,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1a05c183fec..045cf0a6e1a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2005-11-21 Uros Bizjak <uros@kss-loka.si>
+
+ * gcc.dg/fold-div-2.c: New test.
+
2005-11-20 Ian Lance Taylor <ian@airs.com>
PR rtl-optimization/24883
diff --git a/gcc/testsuite/gcc.dg/fold-div-2.c b/gcc/testsuite/gcc.dg/fold-div-2.c
new file mode 100644
index 00000000000..bfd07d1c482
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-div-2.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-ffinite-math-only -fdump-tree-gimple" } */
+
+double f(double x)
+{
+ return x / x;
+}
+
+/* Division should be turned into 1.0. */
+
+/* { dg-final { scan-tree-dump-not " / " "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */
+