+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.
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);
}
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;
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);
}