* fold-const.c (round_up, round_down): Use build_int_cst.
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Aug 2004 16:09:00 +0000 (16:09 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Aug 2004 16:09:00 +0000 (16:09 +0000)
Optimize common case.

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

gcc/ChangeLog
gcc/fold-const.c

index 06a8bd4..eaadc03 100644 (file)
@@ -1,11 +1,17 @@
+2004-08-20  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * fold-const.c (round_up, round_down): Use build_int_cst.
+       Optimize common case.
+
 2004-08-20  Zack Weinberg  <zack@codesourcery.com>
            John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
         * config/pa/pa-protos.h (readonly_data, one_only_readonly_data_section,
        one_only_data_section): Rename to som_readonly_data_section,
        som_one_only_readonly_data_section and som_one_only_data_section.
-        * config/pa/pa.c (ONE_ONLY_TEXT_SECTION_ASM_OP, NEW_TEXT_SECTION_ASM_OP,
-       DEFAULT_TEXT_SECTION_ASM_OP): Delete conditional defines.
+        * config/pa/pa.c (ONE_ONLY_TEXT_SECTION_ASM_OP,
+       NEW_TEXT_SECTION_ASM_OP, DEFAULT_TEXT_SECTION_ASM_OP): Delete
+       conditional defines.
        (som_text_section_asm_op): Replace ONE_ONLY_TEXT_SECTION_ASM_OP,
        NEW_TEXT_SECTION_ASM_OP and DEFAULT_TEXT_SECTION_ASM_OP with actual
        string values.
index 2384bd1..e85ead8 100644 (file)
@@ -10661,30 +10661,39 @@ fold_ignored_result (tree t)
 tree
 round_up (tree value, int divisor)
 {
-  tree div, t;
+  tree div = NULL_TREE;
 
-  if (divisor == 0)
+  if (divisor <= 0)
     abort ();
   if (divisor == 1)
     return value;
 
-  div = size_int_type (divisor, TREE_TYPE (value));
-
   /* See if VALUE is already a multiple of DIVISOR.  If so, we don't
-     have to do anything.  */
-  if (multiple_of_p (TREE_TYPE (value), value, div))
-    return value;
+     have to do anything.  Only do this when we are not given a const,
+     because in that case, this check is more expensive than just
+     doing it. */
+  if (TREE_CODE (value) != INTEGER_CST)
+    {
+      div = size_int_type (divisor, TREE_TYPE (value));
+
+      if (multiple_of_p (TREE_TYPE (value), value, div))
+       return value;
+    }
 
   /* If divisor is a power of two, simplify this to bit manipulation.  */
   if (divisor == (divisor & -divisor))
     {
-      t = size_int_type (divisor - 1, TREE_TYPE (value));
+      tree t;
+      
+      t = build_int_cst (TREE_TYPE (value), divisor - 1, 0);
       value = size_binop (PLUS_EXPR, value, t);
-      t = size_int_type (-divisor, TREE_TYPE (value));
+      t = build_int_cst (TREE_TYPE (value), -divisor, -1);
       value = size_binop (BIT_AND_EXPR, value, t);
     }
   else
     {
+      if (!div)
+       div = size_int_type (divisor, TREE_TYPE (value));
       value = size_binop (CEIL_DIV_EXPR, value, div);
       value = size_binop (MULT_EXPR, value, div);
     }
@@ -10697,9 +10706,9 @@ round_up (tree value, int divisor)
 tree
 round_down (tree value, int divisor)
 {
-  tree div, t;
+  tree div = NULL_TREE;
 
-  if (divisor == 0)
+  if (divisor <= 0)
     abort ();
   if (divisor == 1)
     return value;
@@ -10707,18 +10716,29 @@ round_down (tree value, int divisor)
   div = size_int_type (divisor, TREE_TYPE (value));
 
   /* See if VALUE is already a multiple of DIVISOR.  If so, we don't
-     have to do anything.  */
-  if (multiple_of_p (TREE_TYPE (value), value, div))
-    return value;
+     have to do anything.  Only do this when we are not given a const,
+     because in that case, this check is more expensive than just
+     doing it. */
+  if (TREE_CODE (value) != INTEGER_CST)
+    {
+      div = size_int_type (divisor, TREE_TYPE (value));
+
+      if (multiple_of_p (TREE_TYPE (value), value, div))
+       return value;
+    }
 
   /* If divisor is a power of two, simplify this to bit manipulation.  */
   if (divisor == (divisor & -divisor))
     {
-      t = size_int_type (-divisor, TREE_TYPE (value));
+      tree t;
+      
+      t = build_int_cst (TREE_TYPE (value), -divisor, -1);
       value = size_binop (BIT_AND_EXPR, value, t);
     }
   else
     {
+      if (!div)
+       div = size_int_type (divisor, TREE_TYPE (value));
       value = size_binop (FLOOR_DIV_EXPR, value, div);
       value = size_binop (MULT_EXPR, value, div);
     }