From: Nathan Sidwell Date: Fri, 20 Aug 2004 16:09:00 +0000 (+0000) Subject: fold-const.c (round_up, round_down): Use build_int_cst. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0a936b12eb24c549c87b046ce91cfcafa3eed28f;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 06a8bd405f5..eaadc038c32 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,11 +1,17 @@ +2004-08-20 Nathan Sidwell + + * fold-const.c (round_up, round_down): Use build_int_cst. + Optimize common case. + 2004-08-20 Zack Weinberg John David Anglin * 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. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2384bd1dd23..e85ead88b32 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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); }