Commit 0a936b12 by Nathan Sidwell

fold-const.c (round_up, round_down): Use build_int_cst.

	* fold-const.c (round_up, round_down): Use build_int_cst.
	Optimize common case.

From-SVN: r86329
parent dd8b67a1
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> 2004-08-20 Zack Weinberg <zack@codesourcery.com>
John David Anglin <dave.anglin@nrc-cnrc.gc.ca> John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* config/pa/pa-protos.h (readonly_data, one_only_readonly_data_section, * config/pa/pa-protos.h (readonly_data, one_only_readonly_data_section,
one_only_data_section): Rename to som_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. 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, * config/pa/pa.c (ONE_ONLY_TEXT_SECTION_ASM_OP,
DEFAULT_TEXT_SECTION_ASM_OP): Delete conditional defines. 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, (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 NEW_TEXT_SECTION_ASM_OP and DEFAULT_TEXT_SECTION_ASM_OP with actual
string values. string values.
......
...@@ -10661,30 +10661,39 @@ fold_ignored_result (tree t) ...@@ -10661,30 +10661,39 @@ fold_ignored_result (tree t)
tree tree
round_up (tree value, int divisor) round_up (tree value, int divisor)
{ {
tree div, t; tree div = NULL_TREE;
if (divisor == 0) if (divisor <= 0)
abort (); abort ();
if (divisor == 1) if (divisor == 1)
return value; return value;
div = size_int_type (divisor, TREE_TYPE (value));
/* See if VALUE is already a multiple of DIVISOR. If so, we don't /* See if VALUE is already a multiple of DIVISOR. If so, we don't
have to do anything. */ have to do anything. Only do this when we are not given a const,
if (multiple_of_p (TREE_TYPE (value), value, div)) because in that case, this check is more expensive than just
return value; 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 is a power of two, simplify this to bit manipulation. */
if (divisor == (divisor & -divisor)) 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); 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); value = size_binop (BIT_AND_EXPR, value, t);
} }
else else
{ {
if (!div)
div = size_int_type (divisor, TREE_TYPE (value));
value = size_binop (CEIL_DIV_EXPR, value, div); value = size_binop (CEIL_DIV_EXPR, value, div);
value = size_binop (MULT_EXPR, value, div); value = size_binop (MULT_EXPR, value, div);
} }
...@@ -10697,9 +10706,9 @@ round_up (tree value, int divisor) ...@@ -10697,9 +10706,9 @@ round_up (tree value, int divisor)
tree tree
round_down (tree value, int divisor) round_down (tree value, int divisor)
{ {
tree div, t; tree div = NULL_TREE;
if (divisor == 0) if (divisor <= 0)
abort (); abort ();
if (divisor == 1) if (divisor == 1)
return value; return value;
...@@ -10707,18 +10716,29 @@ round_down (tree value, int divisor) ...@@ -10707,18 +10716,29 @@ round_down (tree value, int divisor)
div = size_int_type (divisor, TREE_TYPE (value)); div = size_int_type (divisor, TREE_TYPE (value));
/* See if VALUE is already a multiple of DIVISOR. If so, we don't /* See if VALUE is already a multiple of DIVISOR. If so, we don't
have to do anything. */ have to do anything. Only do this when we are not given a const,
if (multiple_of_p (TREE_TYPE (value), value, div)) because in that case, this check is more expensive than just
return value; 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 is a power of two, simplify this to bit manipulation. */
if (divisor == (divisor & -divisor)) 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); value = size_binop (BIT_AND_EXPR, value, t);
} }
else else
{ {
if (!div)
div = size_int_type (divisor, TREE_TYPE (value));
value = size_binop (FLOOR_DIV_EXPR, value, div); value = size_binop (FLOOR_DIV_EXPR, value, div);
value = size_binop (MULT_EXPR, value, div); value = size_binop (MULT_EXPR, value, div);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment