OSDN Git Service

* fold-const.c (fold_binary) <RDIV_EXPR>: Optimize A / A to 1.0
authoruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 21 Nov 2005 07:49:47 +0000 (07:49 +0000)
committeruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 21 Nov 2005 07:49:47 +0000 (07:49 +0000)
        if we don't care about NaNs or Infinities.

testsuite:

        * gcc.dg/fold-div-2.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107282 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/fold-div-2.c [new file with mode: 0644]

index 630bebc..b4ff1f8 100644 (file)
@@ -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
index c4dd4f9..e7f550b 100644 (file)
@@ -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,
index 1a05c18..045cf0a 100644 (file)
@@ -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 (file)
index 0000000..bfd07d1
--- /dev/null
@@ -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" } } */
+