]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.c (fold_binary): Optimize A / A to 1.0 if we don't care about NaNs or...
authorUros Bizjak <uros@kss-loka.si>
Mon, 21 Nov 2005 07:49:47 +0000 (08:49 +0100)
committerUros Bizjak <uros@gcc.gnu.org>
Mon, 21 Nov 2005 07:49:47 +0000 (08:49 +0100)
        * fold-const.c (fold_binary) <RDIV_EXPR>: Optimize A / A to 1.0
        if we don't care about NaNs or Infinities.

testsuite:

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

From-SVN: r107282

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

index 630bebc1bbfc2b4a3a6e28bb561f9ee0c97ea502..b4ff1f894458c198c652d880941edad39f77212c 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 c4dd4f955a7ebd43b323654815840b3a14bd9fdb..e7f550b2038ae43d815f7ab9d3dacbb0d84fd2fa 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 1a05c183fec54af9cfbd5bb817c8c49e0a5b5438..045cf0a6e1a0487abce066b5d3550f936ab487a2 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" } } */
+