aboutsummaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2004-07-09 18:52:53 -0700
committerRichard Henderson <rth@gcc.gnu.org>2004-07-09 18:52:53 -0700
commite4d3eef11d6ed460db6aa66fea489bd3e0c9f577 (patch)
tree236f16934f66ba6982429b03b99f0240e991c0d1 /gcc/stor-layout.c
parentffe384ff8643d92dc213b386b3dadb8d90c4b0d1 (diff)
downloadgcc-e4d3eef11d6ed460db6aa66fea489bd3e0c9f577.zip
gcc-e4d3eef11d6ed460db6aa66fea489bd3e0c9f577.tar.gz
gcc-e4d3eef11d6ed460db6aa66fea489bd3e0c9f577.tar.bz2
builtins.c (std_gimplify_va_arg_expr): Deny ARGS_GROW_DOWNWARD.
* builtins.c (std_gimplify_va_arg_expr): Deny ARGS_GROW_DOWNWARD. Always align upward to arg boundary. Use size_in_bytes/round_up. Maintain type-correctness of constants. * stor-layout.c (round_up, round_down): Special-case powers of 2. From-SVN: r84430
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index cf97159..6897685 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -274,9 +274,24 @@ get_mode_alignment (enum machine_mode mode)
tree
round_up (tree value, int divisor)
{
- tree arg = size_int_type (divisor, TREE_TYPE (value));
+ tree t;
+
+ /* 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));
+ value = size_binop (PLUS_EXPR, value, t);
+ t = size_int_type (-divisor, TREE_TYPE (value));
+ value = size_binop (BIT_AND_EXPR, value, t);
+ }
+ else
+ {
+ t = size_int_type (divisor, TREE_TYPE (value));
+ value = size_binop (CEIL_DIV_EXPR, value, t);
+ value = size_binop (MULT_EXPR, value, t);
+ }
- return size_binop (MULT_EXPR, size_binop (CEIL_DIV_EXPR, value, arg), arg);
+ return value;
}
/* Likewise, but round down. */
@@ -284,9 +299,22 @@ round_up (tree value, int divisor)
tree
round_down (tree value, int divisor)
{
- tree arg = size_int_type (divisor, TREE_TYPE (value));
+ tree t;
+
+ /* If divisor is a power of two, simplify this to bit manipulation. */
+ if (divisor == (divisor & -divisor))
+ {
+ t = size_int_type (-divisor, TREE_TYPE (value));
+ value = size_binop (BIT_AND_EXPR, value, t);
+ }
+ else
+ {
+ t = size_int_type (divisor, TREE_TYPE (value));
+ value = size_binop (FLOOR_DIV_EXPR, value, t);
+ value = size_binop (MULT_EXPR, value, t);
+ }
- return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, arg), arg);
+ return value;
}
/* Subroutine of layout_decl: Force alignment required for the data type.