]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* simplify-rtx.c (simplify_binary_operation): Constant fold
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 5 Apr 2004 03:14:13 +0000 (03:14 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 5 Apr 2004 03:14:13 +0000 (03:14 +0000)
DIV, MOD, UDIV and UMOD using div_and_round_double.

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

gcc/ChangeLog
gcc/simplify-rtx.c

index 582add276f361c19bc841aa97e13dbfa44249bef..74005c47623f6d989b183d7c56202a988cdf7a92 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 0058589dc438158c1a929666d8c52112986c83f9..0d283cd250569b644b36060de73139801c765975 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;