simplify-rtx.c (simplify_binary_operation): Constant fold DIV, MOD, UDIV and UMOD...
authorRoger Sayle <roger@eyesopen.com>
Mon, 5 Apr 2004 03:14:13 +0000 (03:14 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Mon, 5 Apr 2004 03:14:13 +0000 (03:14 +0000)
* simplify-rtx.c (simplify_binary_operation): Constant fold
DIV, MOD, UDIV and UMOD using div_and_round_double.

From-SVN: r80420

gcc/ChangeLog
gcc/simplify-rtx.c

index 582add2..74005c4 100644 (file)
@@ -1,3 +1,8 @@
+2004-04-04  Roger Sayle  <roger@eyesopen.com>
+
+       * simplify-rtx.c (simplify_binary_operation): Constant fold
+       DIV, MOD, UDIV and UMOD using div_and_round_double.
+
 2004-04-04  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/14804
index 0058589..0d283cd 100644 (file)
@@ -1285,8 +1285,8 @@ simplify_binary_operation (enum rtx_code code, enum machine_mode mode,
       && (GET_CODE (trueop1) == CONST_DOUBLE
          || GET_CODE (trueop1) == CONST_INT))
     {
-      unsigned HOST_WIDE_INT l1, l2, lv;
-      HOST_WIDE_INT h1, h2, hv;
+      unsigned HOST_WIDE_INT l1, l2, lv, lt;
+      HOST_WIDE_INT h1, h2, hv, ht;
 
       if (GET_CODE (trueop0) == CONST_DOUBLE)
        l1 = CONST_DOUBLE_LOW (trueop0), h1 = CONST_DOUBLE_HIGH (trueop0);
@@ -1315,10 +1315,29 @@ simplify_binary_operation (enum rtx_code code, enum machine_mode mode,
          mul_double (l1, h1, l2, h2, &lv, &hv);
          break;
 
-       case DIV:  case MOD:   case UDIV:  case UMOD:
-         /* We'd need to include tree.h to do this and it doesn't seem worth
-            it.  */
-         return 0;
+       case DIV:
+         if (div_and_round_double (TRUNC_DIV_EXPR, 0, l1, h1, l2, h2,
+                                   &lv, &hv, &lt, &ht))
+           return 0;
+         break;
+
+       case MOD:
+         if (div_and_round_double (TRUNC_DIV_EXPR, 0, l1, h1, l2, h2,
+                                   &lt, &ht, &lv, &hv))
+           return 0;
+         break;
+
+       case UDIV:
+         if (div_and_round_double (TRUNC_DIV_EXPR, 1, l1, h1, l2, h2,
+                                   &lv, &hv, &lt, &ht))
+           return 0;
+         break;
+
+       case UMOD:
+         if (div_and_round_double (TRUNC_DIV_EXPR, 1, l1, h1, l2, h2,
+                                   &lt, &ht, &lv, &hv))
+           return 0;
+         break;
 
        case AND:
          lv = l1 & l2, hv = h1 & h2;