diff mbox series

[047/nnn] poly_int: argument sizes

Message ID 878tg1n5mf.fsf@linaro.org
State New
Headers show
Series [047/nnn] poly_int: argument sizes | expand

Commit Message

Richard Sandiford Oct. 23, 2017, 5:20 p.m. UTC
This patch changes various bits of state related to argument sizes so
that they have type poly_int64 rather than HOST_WIDE_INT.  This includes:

- incoming_args::pops_args and incoming_args::size
- rtl_data::outgoing_args_size
- pending_stack_adjust
- stack_pointer_delta
- stack_usage::pushed_stack_size
- args_size::constant

It also changes TARGET_RETURN_POPS_ARGS so that the size of the
arguments passed in and the size returned by the hook are both
poly_int64s.


2017-10-23  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* target.def (return_pops_args): Treat both the input and output
	sizes as poly_int64s rather than HOST_WIDE_INTS.
	* targhooks.h (default_return_pops_args): Update accordingly.
	* targhooks.c (default_return_pops_args): Likewise.
	* doc/tm.texi: Regenerate.
	* emit-rtl.h (incoming_args): Change pops_args, size and
	outgoing_args_size from int to poly_int64_pod.
	* function.h (expr_status): Change x_pending_stack_adjust and
	x_stack_pointer_delta from int to poly_int64.
	(args_size::constant): Change from HOST_WIDE_INT to poly_int64.
	(ARGS_SIZE_RTX): Update accordingly.
	* calls.c (highest_outgoing_arg_in_use): Change from int to
	unsigned int.
	(stack_usage_watermark, stored_args_watermark): New variables.
	(stack_region_maybe_used_p, mark_stack_region_used): New functions.
	(emit_call_1): Change the stack_size and rounded_stack_size
	parameters from HOST_WIDE_INT to poly_int64.  Track n_popped
	as a poly_int64.
	(save_fixed_argument_area): Check stack_usage_watermark.
	(initialize_argument_information): Change old_pending_adj from
	a HOST_WIDE_INT * to a poly_int64_pod *.
	(compute_argument_block_size): Return the size as a poly_int64
	rather than an int.
	(finalize_must_preallocate): Track polynomial argument sizes.
	(compute_argument_addresses): Likewise.
	(internal_arg_pointer_based_exp): Track polynomial offsets.
	(mem_overlaps_already_clobbered_arg_p): Rename to...
	(mem_might_overlap_already_clobbered_arg_p): ...this and take the
	size as a poly_uint64 rather than an unsigned HOST_WIDE_INT.
	Check stored_args_used_watermark.
	(load_register_parameters): Update accordingly.
	(check_sibcall_argument_overlap_1): Likewise.
	(combine_pending_stack_adjustment_and_call): Take the unadjusted
	args size as a poly_int64 rather than an int.  Return a bool
	indicating whether the optimization was possible and return
	the new adjustment by reference.
	(check_sibcall_argument_overlap): Track polynomail argument sizes.
	Update stored_args_watermark.
	(can_implement_as_sibling_call_p): Handle polynomial argument sizes.
	(expand_call): Likewise.  Maintain stack_usage_watermark and
	stored_args_watermark.  Update calls to
	combine_pending_stack_adjustment_and_call.
	(emit_library_call_value_1): Handle polynomial argument sizes.
	Call stack_region_maybe_used_p and mark_stack_region_used.
	Maintain stack_usage_watermark.
	(store_one_arg): Likewise.  Update call to
	mem_overlaps_already_clobbered_arg_p.
	* config/arm/arm.c (arm_output_function_prologue): Add a cast to
	HOST_WIDE_INT.
	* config/avr/avr.c (avr_outgoing_args_size): Likewise.
	* config/microblaze/microblaze.c (microblaze_function_prologue):
	Likewise.
	* config/cr16/cr16.c (cr16_return_pops_args): Update for new
	TARGET_RETURN_POPS_ARGS interface.
	(cr16_compute_frame, cr16_initial_elimination_offset): Add casts
	to HOST_WIDE_INT.
	* config/ft32/ft32.c (ft32_compute_frame): Likewise.
	* config/i386/i386.c (ix86_return_pops_args): Update for new
	TARGET_RETURN_POPS_ARGS interface.
	(ix86_expand_split_stack_prologue): Add a cast to HOST_WIDE_INT.
	* config/moxie/moxie.c (moxie_compute_frame): Likewise.
	* config/m68k/m68k.c (m68k_return_pops_args): Update for new
	TARGET_RETURN_POPS_ARGS interface.
	* config/vax/vax.c (vax_return_pops_args): Likewise.
	* config/pa/pa.h (STACK_POINTER_OFFSET): Add a cast to poly_int64.
	(EXIT_IGNORE_STACK): Update reference to crtl->outgoing_args_size.
	* config/arm/arm.h (CALLER_INTERWORKING_SLOT_SIZE): Likewise.
	* config/powerpcspe/aix.h (STACK_DYNAMIC_OFFSET): Likewise.
	* config/powerpcspe/darwin.h (STACK_DYNAMIC_OFFSET): Likewise.
	* config/powerpcspe/powerpcspe.h (STACK_DYNAMIC_OFFSET): Likewise.
	* config/rs6000/aix.h (STACK_DYNAMIC_OFFSET): Likewise.
	* config/rs6000/darwin.h (STACK_DYNAMIC_OFFSET): Likewise.
	* config/rs6000/rs6000.h (STACK_DYNAMIC_OFFSET): Likewise.
	* dojump.h (saved_pending_stack_adjust): Change x_pending_stack_adjust
	and x_stack_pointer_delta from int to poly_int64.
	* dojump.c (do_pending_stack_adjust): Update accordingly.
	* explow.c (allocate_dynamic_stack_space): Handle polynomial
	stack_pointer_deltas.
	* function.c (STACK_DYNAMIC_OFFSET): Add a cast to poly_int64.
	(pad_to_arg_alignment): Track polynomial offsets.
	(assign_parm_find_stack_rtl): Likewise.
	(assign_parms, locate_and_pad_parm): Handle polynomial argument sizes.
	* toplev.c (output_stack_usage): Update reference to
	current_function_pushed_stack_size.

Comments

Jeff Law Dec. 6, 2017, 8:57 p.m. UTC | #1
On 10/23/2017 11:20 AM, Richard Sandiford wrote:
> This patch changes various bits of state related to argument sizes so

> that they have type poly_int64 rather than HOST_WIDE_INT.  This includes:

> 

> - incoming_args::pops_args and incoming_args::size

> - rtl_data::outgoing_args_size

> - pending_stack_adjust

> - stack_pointer_delta

> - stack_usage::pushed_stack_size

> - args_size::constant

> 

> It also changes TARGET_RETURN_POPS_ARGS so that the size of the

> arguments passed in and the size returned by the hook are both

> poly_int64s.

> 

> 

> 2017-10-23  Richard Sandiford  <richard.sandiford@linaro.org>

> 	    Alan Hayward  <alan.hayward@arm.com>

> 	    David Sherwood  <david.sherwood@arm.com>

> 

> gcc/

> 	* target.def (return_pops_args): Treat both the input and output

> 	sizes as poly_int64s rather than HOST_WIDE_INTS.

> 	* targhooks.h (default_return_pops_args): Update accordingly.

> 	* targhooks.c (default_return_pops_args): Likewise.

> 	* doc/tm.texi: Regenerate.

> 	* emit-rtl.h (incoming_args): Change pops_args, size and

> 	outgoing_args_size from int to poly_int64_pod.

> 	* function.h (expr_status): Change x_pending_stack_adjust and

> 	x_stack_pointer_delta from int to poly_int64.

> 	(args_size::constant): Change from HOST_WIDE_INT to poly_int64.

> 	(ARGS_SIZE_RTX): Update accordingly.

> 	* calls.c (highest_outgoing_arg_in_use): Change from int to

> 	unsigned int.

> 	(stack_usage_watermark, stored_args_watermark): New variables.

> 	(stack_region_maybe_used_p, mark_stack_region_used): New functions.

> 	(emit_call_1): Change the stack_size and rounded_stack_size

> 	parameters from HOST_WIDE_INT to poly_int64.  Track n_popped

> 	as a poly_int64.

> 	(save_fixed_argument_area): Check stack_usage_watermark.

> 	(initialize_argument_information): Change old_pending_adj from

> 	a HOST_WIDE_INT * to a poly_int64_pod *.

> 	(compute_argument_block_size): Return the size as a poly_int64

> 	rather than an int.

> 	(finalize_must_preallocate): Track polynomial argument sizes.

> 	(compute_argument_addresses): Likewise.

> 	(internal_arg_pointer_based_exp): Track polynomial offsets.

> 	(mem_overlaps_already_clobbered_arg_p): Rename to...

> 	(mem_might_overlap_already_clobbered_arg_p): ...this and take the

> 	size as a poly_uint64 rather than an unsigned HOST_WIDE_INT.

> 	Check stored_args_used_watermark.

> 	(load_register_parameters): Update accordingly.

> 	(check_sibcall_argument_overlap_1): Likewise.

> 	(combine_pending_stack_adjustment_and_call): Take the unadjusted

> 	args size as a poly_int64 rather than an int.  Return a bool

> 	indicating whether the optimization was possible and return

> 	the new adjustment by reference.

> 	(check_sibcall_argument_overlap): Track polynomail argument sizes.

> 	Update stored_args_watermark.

> 	(can_implement_as_sibling_call_p): Handle polynomial argument sizes.

> 	(expand_call): Likewise.  Maintain stack_usage_watermark and

> 	stored_args_watermark.  Update calls to

> 	combine_pending_stack_adjustment_and_call.

> 	(emit_library_call_value_1): Handle polynomial argument sizes.

> 	Call stack_region_maybe_used_p and mark_stack_region_used.

> 	Maintain stack_usage_watermark.

> 	(store_one_arg): Likewise.  Update call to

> 	mem_overlaps_already_clobbered_arg_p.

> 	* config/arm/arm.c (arm_output_function_prologue): Add a cast to

> 	HOST_WIDE_INT.

> 	* config/avr/avr.c (avr_outgoing_args_size): Likewise.

> 	* config/microblaze/microblaze.c (microblaze_function_prologue):

> 	Likewise.

> 	* config/cr16/cr16.c (cr16_return_pops_args): Update for new

> 	TARGET_RETURN_POPS_ARGS interface.

> 	(cr16_compute_frame, cr16_initial_elimination_offset): Add casts

> 	to HOST_WIDE_INT.

> 	* config/ft32/ft32.c (ft32_compute_frame): Likewise.

> 	* config/i386/i386.c (ix86_return_pops_args): Update for new

> 	TARGET_RETURN_POPS_ARGS interface.

> 	(ix86_expand_split_stack_prologue): Add a cast to HOST_WIDE_INT.

> 	* config/moxie/moxie.c (moxie_compute_frame): Likewise.

> 	* config/m68k/m68k.c (m68k_return_pops_args): Update for new

> 	TARGET_RETURN_POPS_ARGS interface.

> 	* config/vax/vax.c (vax_return_pops_args): Likewise.

> 	* config/pa/pa.h (STACK_POINTER_OFFSET): Add a cast to poly_int64.

> 	(EXIT_IGNORE_STACK): Update reference to crtl->outgoing_args_size.

> 	* config/arm/arm.h (CALLER_INTERWORKING_SLOT_SIZE): Likewise.

> 	* config/powerpcspe/aix.h (STACK_DYNAMIC_OFFSET): Likewise.

> 	* config/powerpcspe/darwin.h (STACK_DYNAMIC_OFFSET): Likewise.

> 	* config/powerpcspe/powerpcspe.h (STACK_DYNAMIC_OFFSET): Likewise.

> 	* config/rs6000/aix.h (STACK_DYNAMIC_OFFSET): Likewise.

> 	* config/rs6000/darwin.h (STACK_DYNAMIC_OFFSET): Likewise.

> 	* config/rs6000/rs6000.h (STACK_DYNAMIC_OFFSET): Likewise.

> 	* dojump.h (saved_pending_stack_adjust): Change x_pending_stack_adjust

> 	and x_stack_pointer_delta from int to poly_int64.

> 	* dojump.c (do_pending_stack_adjust): Update accordingly.

> 	* explow.c (allocate_dynamic_stack_space): Handle polynomial

> 	stack_pointer_deltas.

> 	* function.c (STACK_DYNAMIC_OFFSET): Add a cast to poly_int64.

> 	(pad_to_arg_alignment): Track polynomial offsets.

> 	(assign_parm_find_stack_rtl): Likewise.

> 	(assign_parms, locate_and_pad_parm): Handle polynomial argument sizes.

> 	* toplev.c (output_stack_usage): Update reference to

> 	current_function_pushed_stack_size.

I haven't been able to convince myself that the changes to the
stack_usage_map are correct, particularly in the case where the
UPPER_BOUND is not constant.  But I'm willing to let it go given the
only target that could potentially be affected would be SVE and I'd
expect that if you'd gotten it wrong it would have showed up in your
testing.

I'm also slightly worried about how we handle ARGS_GROW_DOWNWARD targets
(pa, stormy16).  I couldn't convince myself those changes were correct
either.  Again, I'm willing on fall back to lean on your extensive
experience and testing here.

Of all the patches to-date I've looked at, this one worries me the most
(which is why it's next to last according to my records).  The potential
for a goof in the argument setup, padding, stack save area, and the
consequences for such a goof worry me.

I'm going to conditionally ack this -- my condition is that you
re-review the the calls.c/function.c changes as well.

Jeff
Richard Sandiford Dec. 20, 2017, 11:37 a.m. UTC | #2
Jeff Law <law@redhat.com> writes:
> On 10/23/2017 11:20 AM, Richard Sandiford wrote:

>> This patch changes various bits of state related to argument sizes so

>> that they have type poly_int64 rather than HOST_WIDE_INT.  This includes:

>> 

>> - incoming_args::pops_args and incoming_args::size

>> - rtl_data::outgoing_args_size

>> - pending_stack_adjust

>> - stack_pointer_delta

>> - stack_usage::pushed_stack_size

>> - args_size::constant

>> 

>> It also changes TARGET_RETURN_POPS_ARGS so that the size of the

>> arguments passed in and the size returned by the hook are both

>> poly_int64s.

>> 

>> 

>> 2017-10-23  Richard Sandiford  <richard.sandiford@linaro.org>

>> 	    Alan Hayward  <alan.hayward@arm.com>

>> 	    David Sherwood  <david.sherwood@arm.com>

>> 

>> gcc/

>> 	* target.def (return_pops_args): Treat both the input and output

>> 	sizes as poly_int64s rather than HOST_WIDE_INTS.

>> 	* targhooks.h (default_return_pops_args): Update accordingly.

>> 	* targhooks.c (default_return_pops_args): Likewise.

>> 	* doc/tm.texi: Regenerate.

>> 	* emit-rtl.h (incoming_args): Change pops_args, size and

>> 	outgoing_args_size from int to poly_int64_pod.

>> 	* function.h (expr_status): Change x_pending_stack_adjust and

>> 	x_stack_pointer_delta from int to poly_int64.

>> 	(args_size::constant): Change from HOST_WIDE_INT to poly_int64.

>> 	(ARGS_SIZE_RTX): Update accordingly.

>> 	* calls.c (highest_outgoing_arg_in_use): Change from int to

>> 	unsigned int.

>> 	(stack_usage_watermark, stored_args_watermark): New variables.

>> 	(stack_region_maybe_used_p, mark_stack_region_used): New functions.

>> 	(emit_call_1): Change the stack_size and rounded_stack_size

>> 	parameters from HOST_WIDE_INT to poly_int64.  Track n_popped

>> 	as a poly_int64.

>> 	(save_fixed_argument_area): Check stack_usage_watermark.

>> 	(initialize_argument_information): Change old_pending_adj from

>> 	a HOST_WIDE_INT * to a poly_int64_pod *.

>> 	(compute_argument_block_size): Return the size as a poly_int64

>> 	rather than an int.

>> 	(finalize_must_preallocate): Track polynomial argument sizes.

>> 	(compute_argument_addresses): Likewise.

>> 	(internal_arg_pointer_based_exp): Track polynomial offsets.

>> 	(mem_overlaps_already_clobbered_arg_p): Rename to...

>> 	(mem_might_overlap_already_clobbered_arg_p): ...this and take the

>> 	size as a poly_uint64 rather than an unsigned HOST_WIDE_INT.

>> 	Check stored_args_used_watermark.

>> 	(load_register_parameters): Update accordingly.

>> 	(check_sibcall_argument_overlap_1): Likewise.

>> 	(combine_pending_stack_adjustment_and_call): Take the unadjusted

>> 	args size as a poly_int64 rather than an int.  Return a bool

>> 	indicating whether the optimization was possible and return

>> 	the new adjustment by reference.

>> 	(check_sibcall_argument_overlap): Track polynomail argument sizes.

>> 	Update stored_args_watermark.

>> 	(can_implement_as_sibling_call_p): Handle polynomial argument sizes.

>> 	(expand_call): Likewise.  Maintain stack_usage_watermark and

>> 	stored_args_watermark.  Update calls to

>> 	combine_pending_stack_adjustment_and_call.

>> 	(emit_library_call_value_1): Handle polynomial argument sizes.

>> 	Call stack_region_maybe_used_p and mark_stack_region_used.

>> 	Maintain stack_usage_watermark.

>> 	(store_one_arg): Likewise.  Update call to

>> 	mem_overlaps_already_clobbered_arg_p.

>> 	* config/arm/arm.c (arm_output_function_prologue): Add a cast to

>> 	HOST_WIDE_INT.

>> 	* config/avr/avr.c (avr_outgoing_args_size): Likewise.

>> 	* config/microblaze/microblaze.c (microblaze_function_prologue):

>> 	Likewise.

>> 	* config/cr16/cr16.c (cr16_return_pops_args): Update for new

>> 	TARGET_RETURN_POPS_ARGS interface.

>> 	(cr16_compute_frame, cr16_initial_elimination_offset): Add casts

>> 	to HOST_WIDE_INT.

>> 	* config/ft32/ft32.c (ft32_compute_frame): Likewise.

>> 	* config/i386/i386.c (ix86_return_pops_args): Update for new

>> 	TARGET_RETURN_POPS_ARGS interface.

>> 	(ix86_expand_split_stack_prologue): Add a cast to HOST_WIDE_INT.

>> 	* config/moxie/moxie.c (moxie_compute_frame): Likewise.

>> 	* config/m68k/m68k.c (m68k_return_pops_args): Update for new

>> 	TARGET_RETURN_POPS_ARGS interface.

>> 	* config/vax/vax.c (vax_return_pops_args): Likewise.

>> 	* config/pa/pa.h (STACK_POINTER_OFFSET): Add a cast to poly_int64.

>> 	(EXIT_IGNORE_STACK): Update reference to crtl->outgoing_args_size.

>> 	* config/arm/arm.h (CALLER_INTERWORKING_SLOT_SIZE): Likewise.

>> 	* config/powerpcspe/aix.h (STACK_DYNAMIC_OFFSET): Likewise.

>> 	* config/powerpcspe/darwin.h (STACK_DYNAMIC_OFFSET): Likewise.

>> 	* config/powerpcspe/powerpcspe.h (STACK_DYNAMIC_OFFSET): Likewise.

>> 	* config/rs6000/aix.h (STACK_DYNAMIC_OFFSET): Likewise.

>> 	* config/rs6000/darwin.h (STACK_DYNAMIC_OFFSET): Likewise.

>> 	* config/rs6000/rs6000.h (STACK_DYNAMIC_OFFSET): Likewise.

>> 	* dojump.h (saved_pending_stack_adjust): Change x_pending_stack_adjust

>> 	and x_stack_pointer_delta from int to poly_int64.

>> 	* dojump.c (do_pending_stack_adjust): Update accordingly.

>> 	* explow.c (allocate_dynamic_stack_space): Handle polynomial

>> 	stack_pointer_deltas.

>> 	* function.c (STACK_DYNAMIC_OFFSET): Add a cast to poly_int64.

>> 	(pad_to_arg_alignment): Track polynomial offsets.

>> 	(assign_parm_find_stack_rtl): Likewise.

>> 	(assign_parms, locate_and_pad_parm): Handle polynomial argument sizes.

>> 	* toplev.c (output_stack_usage): Update reference to

>> 	current_function_pushed_stack_size.

> I haven't been able to convince myself that the changes to the

> stack_usage_map are correct, particularly in the case where the

> UPPER_BOUND is not constant.  But I'm willing to let it go given the

> only target that could potentially be affected would be SVE and I'd

> expect that if you'd gotten it wrong it would have showed up in your

> testing.

>

> I'm also slightly worried about how we handle ARGS_GROW_DOWNWARD targets

> (pa, stormy16).  I couldn't convince myself those changes were correct

> either.  Again, I'm willing on fall back to lean on your extensive

> experience and testing here.

>

> Of all the patches to-date I've looked at, this one worries me the most

> (which is why it's next to last according to my records).  The potential

> for a goof in the argument setup, padding, stack save area, and the

> consequences for such a goof worry me.

>

> I'm going to conditionally ack this -- my condition is that you

> re-review the the calls.c/function.c changes as well.


I agree this is probably the least obvious of the changes.  I've had
another look and I still think the approach is OK.

For stack_usage_map: we're trying to detect whether an instruction
references a region of stack that has already been clobbered.
We can conservatively do this as a range from the lowest possible byte
offset in the region to the highest possible byte offset in the region.
This works both when recording a clobber and when testing for an overlap
with a previous clobber.

For polynomial lower bounds, the lowest possible offset is given by
constant_lower_bound.  For polynomial upper bounds, the highest
possible offset is HOST_WIDE_INT_M1U (since we track unsigned offsets
from a zero base).  But it's not possible to have the stack_usage_map
array itself go up to HOST_WIDE_INT_M1U, so instead, the watermark
records the lowest lower bound whose corresponding upper bound is
HOST_WIDE_INT_M1U, so that every index of stack_usage_map starting at
the watermark is conceptually set.

The patch doesn't really change the handling of ARGS_GROW_DOWNWARD,
it just rewrites the tests into a different form.  E.g. there were
two instances of code like:

                  if (ARGS_GROW_DOWNWARD)
                    highest_outgoing_arg_in_use
                      = MAX (initial_highest_arg_in_use, needed + 1);
                  else
                    highest_outgoing_arg_in_use
                      = MAX (initial_highest_arg_in_use, needed);

and the patch splits out the calculation of the second MAX argument:

                  poly_int64 limit = needed;
                  if (ARGS_GROW_DOWNWARD)
                    limit += 1;

The third ARGS_GROW_DOWNARD-related hunk is for pad_to_arg_alignment.
Previously we had:

          offset_ptr->constant = -sp_offset +
            (ARGS_GROW_DOWNWARD
            ? FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes)
            : CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes));

Expanding FLOOR_ROUND, and using the fact that boundary_in_bytes is
a power of 2, the ARGS_GROW_DOWNARD case is equivalent to:

          offset_ptr->constant = -sp_offset
            + (offset_ptr->constant + sp_offset)
            - ((offset_ptr->constant + sp_offset) & (boundary_in_bytes - 1));

The -sp_offset + sp_offset cancels out, giving:

          offset_ptr->constant
            = offset_ptr->constant
            - ((offset_ptr->constant + sp_offset) & (boundary_in_bytes - 1));

or:

          offset_ptr->constant
            -= (offset_ptr->constant + sp_offset) & (boundary_in_bytes - 1);

But since (offset_ptr->constant + sp_offset) is polynomial, we can't
always calculate this value, so the code is conditional on a call
to known_misalignment:

      if (...
          || !known_misalignment (offset_ptr->constant + sp_offset,
                                  boundary_in_bytes, &misalign))
        ...
      else
        {
          if (ARGS_GROW_DOWNWARD)
            offset_ptr->constant -= misalign;
        
Thanks,
Richard
diff mbox series

Patch

Index: gcc/target.def
===================================================================
--- gcc/target.def	2017-10-23 17:11:40.311071579 +0100
+++ gcc/target.def	2017-10-23 17:19:01.411170305 +0100
@@ -5043,7 +5043,7 @@  arguments pop them but other functions (
 nothing (the caller pops all).  When this convention is in use,\n\
 @var{funtype} is examined to determine whether a function takes a fixed\n\
 number of arguments.",
- int, (tree fundecl, tree funtype, int size),
+ poly_int64, (tree fundecl, tree funtype, poly_int64 size),
  default_return_pops_args)
 
 /* Return a mode wide enough to copy any function value that might be
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h	2017-10-23 17:11:40.312073494 +0100
+++ gcc/targhooks.h	2017-10-23 17:19:01.411170305 +0100
@@ -154,7 +154,7 @@  extern bool default_function_value_regno
 extern rtx default_internal_arg_pointer (void);
 extern rtx default_static_chain (const_tree, bool);
 extern void default_trampoline_init (rtx, tree, rtx);
-extern int default_return_pops_args (tree, tree, int);
+extern poly_int64 default_return_pops_args (tree, tree, poly_int64);
 extern reg_class_t default_branch_target_register_class (void);
 extern reg_class_t default_ira_change_pseudo_allocno_class (int, reg_class_t,
 							    reg_class_t);
Index: gcc/targhooks.c
===================================================================
--- gcc/targhooks.c	2017-10-23 17:11:40.312073494 +0100
+++ gcc/targhooks.c	2017-10-23 17:19:01.411170305 +0100
@@ -1009,10 +1009,8 @@  default_trampoline_init (rtx ARG_UNUSED
   sorry ("nested function trampolines not supported on this target");
 }
 
-int
-default_return_pops_args (tree fundecl ATTRIBUTE_UNUSED,
-			  tree funtype ATTRIBUTE_UNUSED,
-			  int size ATTRIBUTE_UNUSED)
+poly_int64
+default_return_pops_args (tree, tree, poly_int64)
 {
   return 0;
 }
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	2017-10-23 17:11:40.308065835 +0100
+++ gcc/doc/tm.texi	2017-10-23 17:19:01.408170265 +0100
@@ -3822,7 +3822,7 @@  suppresses this behavior and causes the
 stack in its natural location.
 @end defmac
 
-@deftypefn {Target Hook} int TARGET_RETURN_POPS_ARGS (tree @var{fundecl}, tree @var{funtype}, int @var{size})
+@deftypefn {Target Hook} poly_int64 TARGET_RETURN_POPS_ARGS (tree @var{fundecl}, tree @var{funtype}, poly_int64 @var{size})
 This target hook returns the number of bytes of its own arguments that
 a function pops on returning, or 0 if the function pops no arguments
 and the caller must therefore pop them all after the function returns.
Index: gcc/emit-rtl.h
===================================================================
--- gcc/emit-rtl.h	2017-10-23 17:18:53.832514935 +0100
+++ gcc/emit-rtl.h	2017-10-23 17:19:01.409170278 +0100
@@ -28,12 +28,12 @@  struct GTY(()) incoming_args {
   /* Number of bytes of args popped by function being compiled on its return.
      Zero if no bytes are to be popped.
      May affect compilation of return insn or of function epilogue.  */
-  int pops_args;
+  poly_int64_pod pops_args;
 
   /* If function's args have a fixed size, this is that size, in bytes.
      Otherwise, it is -1.
      May affect compilation of return insn or of function epilogue.  */
-  int size;
+  poly_int64_pod size;
 
   /* # bytes the prologue should push and pretend that the caller pushed them.
      The prologue must do this, but only if parms can be passed in
@@ -68,7 +68,7 @@  struct GTY(()) rtl_data {
 
   /* # of bytes of outgoing arguments.  If ACCUMULATE_OUTGOING_ARGS is
      defined, the needed space is pushed by the prologue.  */
-  int outgoing_args_size;
+  poly_int64_pod outgoing_args_size;
 
   /* If nonzero, an RTL expression for the location at which the current
      function returns its result.  If the current function returns its
Index: gcc/function.h
===================================================================
--- gcc/function.h	2017-10-23 17:18:53.834514759 +0100
+++ gcc/function.h	2017-10-23 17:19:01.410170292 +0100
@@ -94,7 +94,7 @@  #define REGNO_POINTER_ALIGN(REGNO) (crtl
 struct GTY(()) expr_status {
   /* Number of units that we should eventually pop off the stack.
      These are the arguments to function calls that have already returned.  */
-  int x_pending_stack_adjust;
+  poly_int64_pod x_pending_stack_adjust;
 
   /* Under some ABIs, it is the caller's responsibility to pop arguments
      pushed for function calls.  A naive implementation would simply pop
@@ -117,7 +117,7 @@  struct GTY(()) expr_status {
      boundary can be momentarily unaligned while pushing the arguments.
      Record the delta since last aligned boundary here in order to get
      stack alignment in the nested function calls working right.  */
-  int x_stack_pointer_delta;
+  poly_int64_pod x_stack_pointer_delta;
 
   /* Nonzero means __builtin_saveregs has already been done in this function.
      The value is the pseudoreg containing the value __builtin_saveregs
@@ -200,9 +200,10 @@  struct GTY(()) stack_usage
      meaningful only if has_unbounded_dynamic_stack_size is zero.  */
   HOST_WIDE_INT dynamic_stack_size;
 
-  /* # of bytes of space pushed onto the stack after the prologue.  If
-     !ACCUMULATE_OUTGOING_ARGS, it contains the outgoing arguments.  */
-  int pushed_stack_size;
+  /* Upper bound on the number of bytes pushed onto the stack after the
+     prologue.  If !ACCUMULATE_OUTGOING_ARGS, it contains the outgoing
+     arguments.  */
+  poly_int64 pushed_stack_size;
 
   /* Nonzero if the amount of stack space allocated dynamically cannot
      be bounded at compile-time.  */
@@ -476,7 +477,7 @@  extern struct machine_function * (*init_
 
 struct args_size
 {
-  HOST_WIDE_INT constant;
+  poly_int64_pod constant;
   tree var;
 };
 
@@ -538,7 +539,7 @@  #define ARGS_SIZE_TREE(SIZE)					\
 
 /* Convert the implicit sum in a `struct args_size' into an rtx.  */
 #define ARGS_SIZE_RTX(SIZE)					\
-((SIZE).var == 0 ? GEN_INT ((SIZE).constant)			\
+((SIZE).var == 0 ? gen_int_mode ((SIZE).constant, Pmode)	\
  : expand_normal (ARGS_SIZE_TREE (SIZE)))
 
 #define ASLK_REDUCE_ALIGN 1
Index: gcc/calls.c
===================================================================
--- gcc/calls.c	2017-10-23 17:18:57.856161229 +0100
+++ gcc/calls.c	2017-10-23 17:19:01.395170091 +0100
@@ -127,7 +127,11 @@  struct arg_data
 static char *stack_usage_map;
 
 /* Size of STACK_USAGE_MAP.  */
-static int highest_outgoing_arg_in_use;
+static unsigned int highest_outgoing_arg_in_use;
+
+/* Assume that any stack location at this byte index is used,
+   without checking the contents of stack_usage_map.  */
+static unsigned HOST_WIDE_INT stack_usage_watermark = HOST_WIDE_INT_M1U;
 
 /* A bitmap of virtual-incoming stack space.  Bit is set if the corresponding
    stack location's tail call argument has been already stored into the stack.
@@ -136,6 +140,10 @@  struct arg_data
    overwritten with tail call arguments.  */
 static sbitmap stored_args_map;
 
+/* Assume that any virtual-incoming location at this byte index has been
+   stored, without checking the contents of stored_args_map.  */
+static unsigned HOST_WIDE_INT stored_args_watermark;
+
 /* stack_arg_under_construction is nonzero when an argument may be
    initialized with a constructor call (including a C function that
    returns a BLKmode struct) and expand_call must take special action
@@ -143,9 +151,6 @@  struct arg_data
    argument list for the constructor call.  */
 static int stack_arg_under_construction;
 
-static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
-			 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
-			 cumulative_args_t);
 static void precompute_register_parameters (int, struct arg_data *, int *);
 static void store_bounds (struct arg_data *, struct arg_data *);
 static int store_one_arg (struct arg_data *, rtx, int, int, int);
@@ -153,13 +158,6 @@  static void store_unaligned_arguments_in
 static int finalize_must_preallocate (int, int, struct arg_data *,
 				      struct args_size *);
 static void precompute_arguments (int, struct arg_data *);
-static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
-static void initialize_argument_information (int, struct arg_data *,
-					     struct args_size *, int,
-					     tree, tree,
-					     tree, tree, cumulative_args_t, int,
-					     rtx *, int *, int *, int *,
-					     bool *, bool);
 static void compute_argument_addresses (struct arg_data *, rtx, int);
 static rtx rtx_for_function_call (tree, tree);
 static void load_register_parameters (struct arg_data *, int, rtx *, int,
@@ -168,8 +166,6 @@  static int special_function_p (const_tre
 static int check_sibcall_argument_overlap_1 (rtx);
 static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
 
-static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
-						      unsigned int);
 static tree split_complex_types (tree);
 
 #ifdef REG_PARM_STACK_SPACE
@@ -177,6 +173,46 @@  static rtx save_fixed_argument_area (int
 static void restore_fixed_argument_area (rtx, rtx, int, int);
 #endif
 
+/* Return true if bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
+   stack region might already be in use.  */
+
+static bool
+stack_region_maybe_used_p (poly_uint64 lower_bound, poly_uint64 upper_bound,
+			   unsigned int reg_parm_stack_space)
+{
+  unsigned HOST_WIDE_INT const_lower, const_upper;
+  const_lower = constant_lower_bound (lower_bound);
+  if (!upper_bound.is_constant (&const_upper))
+    const_upper = HOST_WIDE_INT_M1U;
+
+  if (const_upper > stack_usage_watermark)
+    return true;
+
+  /* Don't worry about things in the fixed argument area;
+     it has already been saved.  */
+  const_lower = MAX (const_lower, reg_parm_stack_space);
+  const_upper = MIN (const_upper, highest_outgoing_arg_in_use);
+  for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i)
+    if (stack_usage_map[i])
+      return true;
+  return false;
+}
+
+/* Record that bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
+   stack region are now in use.  */
+
+static void
+mark_stack_region_used (poly_uint64 lower_bound, poly_uint64 upper_bound)
+{
+  unsigned HOST_WIDE_INT const_lower, const_upper;
+  const_lower = constant_lower_bound (lower_bound);
+  if (upper_bound.is_constant (&const_upper))
+    for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i)
+      stack_usage_map[i] = 1;
+  else
+    stack_usage_watermark = MIN (stack_usage_watermark, const_lower);
+}
+
 /* Force FUNEXP into a form suitable for the address of a CALL,
    and return that as an rtx.  Also load the static chain register
    if FNDECL is a nested function.
@@ -339,17 +375,17 @@  prepare_call_address (tree fndecl_or_typ
 static void
 emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
 	     tree funtype ATTRIBUTE_UNUSED,
-	     HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
-	     HOST_WIDE_INT rounded_stack_size,
+	     poly_int64 stack_size ATTRIBUTE_UNUSED,
+	     poly_int64 rounded_stack_size,
 	     HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
 	     rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
 	     int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
 	     cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
 {
-  rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
+  rtx rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
   rtx call, funmem, pat;
   int already_popped = 0;
-  HOST_WIDE_INT n_popped = 0;
+  poly_int64 n_popped = 0;
 
   /* Sibling call patterns never pop arguments (no sibcall(_value)_pop
      patterns exist).  Any popping that the callee does on return will
@@ -407,12 +443,12 @@  emit_call_1 (rtx funexp, tree fntree ATT
      if no arguments are actually popped.  If the target does not have
      "call" or "call_value" insns, then we must use the popping versions
      even if the call has no arguments to pop.  */
-  else if (n_popped > 0
+  else if (maybe_nonzero (n_popped)
 	   || !(valreg
 		? targetm.have_call_value ()
 		: targetm.have_call ()))
     {
-      rtx n_pop = GEN_INT (n_popped);
+      rtx n_pop = gen_int_mode (n_popped, Pmode);
 
       /* If this subroutine pops its own args, record that in the call insn
 	 if possible, for the sake of frame pointer elimination.  */
@@ -486,7 +522,7 @@  emit_call_1 (rtx funexp, tree fntree ATT
      if the context of the call as a whole permits.  */
   inhibit_defer_pop = old_inhibit_defer_pop;
 
-  if (n_popped > 0)
+  if (maybe_nonzero (n_popped))
     {
       if (!already_popped)
 	CALL_INSN_FUNCTION_USAGE (call_insn)
@@ -494,7 +530,7 @@  emit_call_1 (rtx funexp, tree fntree ATT
 			       gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
 			       CALL_INSN_FUNCTION_USAGE (call_insn));
       rounded_stack_size -= n_popped;
-      rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
+      rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
       stack_pointer_delta -= n_popped;
 
       add_args_size_note (call_insn, stack_pointer_delta);
@@ -518,7 +554,7 @@  emit_call_1 (rtx funexp, tree fntree ATT
 	 If returning from the subroutine does pop the args, indicate that the
 	 stack pointer will be changed.  */
 
-      if (rounded_stack_size != 0)
+      if (maybe_nonzero (rounded_stack_size))
 	{
 	  if (ecf_flags & ECF_NORETURN)
 	    /* Just pretend we did the pop.  */
@@ -541,8 +577,8 @@  emit_call_1 (rtx funexp, tree fntree ATT
 
      ??? It will be worthwhile to enable combine_stack_adjustments even for
      such machines.  */
-  else if (n_popped)
-    anti_adjust_stack (GEN_INT (n_popped));
+  else if (maybe_nonzero (n_popped))
+    anti_adjust_stack (gen_int_mode (n_popped, Pmode));
 }
 
 /* Determine if the function identified by FNDECL is one with
@@ -1017,8 +1053,8 @@  precompute_register_parameters (int num_
 static rtx
 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
 {
-  int low;
-  int high;
+  unsigned int low;
+  unsigned int high;
 
   /* Compute the boundary of the area that needs to be saved, if any.  */
   high = reg_parm_stack_space;
@@ -1029,7 +1065,7 @@  save_fixed_argument_area (int reg_parm_s
     high = highest_outgoing_arg_in_use;
 
   for (low = 0; low < high; low++)
-    if (stack_usage_map[low] != 0)
+    if (stack_usage_map[low] != 0 || low >= stack_usage_watermark)
       {
 	int num_to_save;
 	machine_mode save_mode;
@@ -1555,7 +1591,8 @@  initialize_argument_information (int num
 				 tree fndecl, tree fntype,
 				 cumulative_args_t args_so_far,
 				 int reg_parm_stack_space,
-				 rtx *old_stack_level, int *old_pending_adj,
+				 rtx *old_stack_level,
+				 poly_int64_pod *old_pending_adj,
 				 int *must_preallocate, int *ecf_flags,
 				 bool *may_tailcall, bool call_from_thunk_p)
 {
@@ -1958,14 +1995,14 @@  initialize_argument_information (int num
    REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
    for arguments passed in registers.  */
 
-static int
+static poly_int64
 compute_argument_block_size (int reg_parm_stack_space,
 			     struct args_size *args_size,
 			     tree fndecl ATTRIBUTE_UNUSED,
 			     tree fntype ATTRIBUTE_UNUSED,
 			     int preferred_stack_boundary ATTRIBUTE_UNUSED)
 {
-  int unadjusted_args_size = args_size->constant;
+  poly_int64 unadjusted_args_size = args_size->constant;
 
   /* For accumulate outgoing args mode we don't need to align, since the frame
      will be already aligned.  Align to STACK_BOUNDARY in order to prevent
@@ -1988,7 +2025,8 @@  compute_argument_block_size (int reg_par
 	  /* We don't handle this case yet.  To handle it correctly we have
 	     to add the delta, round and subtract the delta.
 	     Currently no machine description requires this support.  */
-	  gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
+	  gcc_assert (multiple_p (stack_pointer_delta,
+				  preferred_stack_boundary));
 	  args_size->var = round_up (args_size->var, preferred_stack_boundary);
 	}
 
@@ -2011,15 +2049,13 @@  compute_argument_block_size (int reg_par
       preferred_stack_boundary /= BITS_PER_UNIT;
       if (preferred_stack_boundary < 1)
 	preferred_stack_boundary = 1;
-      args_size->constant = (((args_size->constant
-			       + stack_pointer_delta
-			       + preferred_stack_boundary - 1)
-			      / preferred_stack_boundary
-			      * preferred_stack_boundary)
+      args_size->constant = (aligned_upper_bound (args_size->constant
+						  + stack_pointer_delta,
+						  preferred_stack_boundary)
 			     - stack_pointer_delta);
 
-      args_size->constant = MAX (args_size->constant,
-				 reg_parm_stack_space);
+      args_size->constant = upper_bound (args_size->constant,
+					 reg_parm_stack_space);
 
       if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
 	args_size->constant -= reg_parm_stack_space;
@@ -2124,7 +2160,7 @@  finalize_must_preallocate (int must_prea
   if (! must_preallocate)
     {
       int partial_seen = 0;
-      int copy_to_evaluate_size = 0;
+      poly_int64 copy_to_evaluate_size = 0;
       int i;
 
       for (i = 0; i < num_actuals && ! must_preallocate; i++)
@@ -2149,8 +2185,8 @@  finalize_must_preallocate (int must_prea
 	      += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
 	}
 
-      if (copy_to_evaluate_size * 2 >= args_size->constant
-	  && args_size->constant > 0)
+      if (maybe_nonzero (args_size->constant)
+	  && may_ge (copy_to_evaluate_size * 2, args_size->constant))
 	must_preallocate = 1;
     }
   return must_preallocate;
@@ -2170,10 +2206,14 @@  compute_argument_addresses (struct arg_d
   if (argblock)
     {
       rtx arg_reg = argblock;
-      int i, arg_offset = 0;
+      int i;
+      poly_int64 arg_offset = 0;
 
       if (GET_CODE (argblock) == PLUS)
-	arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
+	{
+	  arg_reg = XEXP (argblock, 0);
+	  arg_offset = rtx_to_poly_int64 (XEXP (argblock, 1));
+	}
 
       for (i = 0; i < num_actuals; i++)
 	{
@@ -2181,7 +2221,7 @@  compute_argument_addresses (struct arg_d
 	  rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
 	  rtx addr;
 	  unsigned int align, boundary;
-	  unsigned int units_on_stack = 0;
+	  poly_uint64 units_on_stack = 0;
 	  machine_mode partial_mode = VOIDmode;
 
 	  /* Skip this parm if it will not be passed on the stack.  */
@@ -2202,7 +2242,7 @@  compute_argument_addresses (struct arg_d
 	      /* Only part of the parameter is being passed on the stack.
 		 Generate a simple memory reference of the correct size.  */
 	      units_on_stack = args[i].locate.size.constant;
-	      unsigned int bits_on_stack = units_on_stack * BITS_PER_UNIT;
+	      poly_uint64 bits_on_stack = units_on_stack * BITS_PER_UNIT;
 	      partial_mode = int_mode_for_size (bits_on_stack, 1).else_blk ();
 	      args[i].stack = gen_rtx_MEM (partial_mode, addr);
 	      set_mem_size (args[i].stack, units_on_stack);
@@ -2215,12 +2255,16 @@  compute_argument_addresses (struct arg_d
 	    }
 	  align = BITS_PER_UNIT;
 	  boundary = args[i].locate.boundary;
+	  poly_int64 offset_val;
 	  if (args[i].locate.where_pad != PAD_DOWNWARD)
 	    align = boundary;
-	  else if (CONST_INT_P (offset))
+	  else if (poly_int_rtx_p (offset, &offset_val))
 	    {
-	      align = INTVAL (offset) * BITS_PER_UNIT | boundary;
-	      align = least_bit_hwi (align);
+	      align = least_bit_hwi (boundary);
+	      unsigned int offset_align
+		= known_alignment (offset_val) * BITS_PER_UNIT;
+	      if (offset_align != 0)
+		align = MIN (align, offset_align);
 	    }
 	  set_mem_align (args[i].stack, align);
 
@@ -2363,12 +2407,13 @@  internal_arg_pointer_based_exp (const_rt
   if (REG_P (rtl) && HARD_REGISTER_P (rtl))
     return NULL_RTX;
 
-  if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1)))
+  poly_int64 offset;
+  if (GET_CODE (rtl) == PLUS && poly_int_rtx_p (XEXP (rtl, 1), &offset))
     {
       rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
       if (val == NULL_RTX || val == pc_rtx)
 	return val;
-      return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1)));
+      return plus_constant (Pmode, val, offset);
     }
 
   /* When called at the topmost level, scan pseudo assignments in between the
@@ -2399,45 +2444,53 @@  internal_arg_pointer_based_exp (const_rt
   return NULL_RTX;
 }
 
-/* Return true if and only if SIZE storage units (usually bytes)
-   starting from address ADDR overlap with already clobbered argument
-   area.  This function is used to determine if we should give up a
-   sibcall.  */
+/* Return true if SIZE bytes starting from address ADDR might overlap an
+   already-clobbered argument area.  This function is used to determine
+   if we should give up a sibcall.  */
 
 static bool
-mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size)
+mem_might_overlap_already_clobbered_arg_p (rtx addr, poly_uint64 size)
 {
-  HOST_WIDE_INT i;
+  poly_int64 i;
+  unsigned HOST_WIDE_INT start, end;
   rtx val;
 
-  if (bitmap_empty_p (stored_args_map))
+  if (bitmap_empty_p (stored_args_map)
+      && stored_args_watermark == HOST_WIDE_INT_M1U)
     return false;
   val = internal_arg_pointer_based_exp (addr, true);
   if (val == NULL_RTX)
     return false;
-  else if (val == pc_rtx)
+  else if (!poly_int_rtx_p (val, &i))
     return true;
-  else
-    i = INTVAL (val);
+
+  if (known_zero (size))
+    return false;
 
   if (STACK_GROWS_DOWNWARD)
     i -= crtl->args.pretend_args_size;
   else
     i += crtl->args.pretend_args_size;
 
-
   if (ARGS_GROW_DOWNWARD)
     i = -i - size;
 
-  if (size > 0)
-    {
-      unsigned HOST_WIDE_INT k;
+  /* We can ignore any references to the function's pretend args,
+     which at this point would manifest as negative values of I.  */
+  if (must_le (i, 0) && must_le (size, poly_uint64 (-i)))
+    return false;
 
-      for (k = 0; k < size; k++)
-	if (i + k < SBITMAP_SIZE (stored_args_map)
-	    && bitmap_bit_p (stored_args_map, i + k))
-	  return true;
-    }
+  start = may_lt (i, 0) ? 0 : constant_lower_bound (i);
+  if (!(i + size).is_constant (&end))
+    end = HOST_WIDE_INT_M1U;
+
+  if (end > stored_args_watermark)
+    return true;
+
+  end = MIN (end, SBITMAP_SIZE (stored_args_map));
+  for (unsigned HOST_WIDE_INT k = start; k < end; ++k)
+    if (bitmap_bit_p (stored_args_map, k))
+      return true;
 
   return false;
 }
@@ -2541,7 +2594,7 @@  load_register_parameters (struct arg_dat
 	         providing that this has non-zero size.  */
 	      if (is_sibcall
 		  && size != 0
-		  && (mem_overlaps_already_clobbered_arg_p
+		  && (mem_might_overlap_already_clobbered_arg_p
 		      (XEXP (args[i].value, 0), size)))
 		*sibcall_failure = 1;
 
@@ -2610,27 +2663,32 @@  load_register_parameters (struct arg_dat
 /* We need to pop PENDING_STACK_ADJUST bytes.  But, if the arguments
    wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
    bytes, then we would need to push some additional bytes to pad the
-   arguments.  So, we compute an adjust to the stack pointer for an
+   arguments.  So, we try to compute an adjust to the stack pointer for an
    amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
    bytes.  Then, when the arguments are pushed the stack will be perfectly
-   aligned.  ARGS_SIZE->CONSTANT is set to the number of bytes that should
-   be popped after the call.  Returns the adjustment.  */
+   aligned.
 
-static int
-combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
+   Return true if this optimization is possible, storing the adjustment
+   in ADJUSTMENT_OUT and setting ARGS_SIZE->CONSTANT to the number of
+   bytes that should be popped after the call.  */
+
+static bool
+combine_pending_stack_adjustment_and_call (poly_int64_pod *adjustment_out,
+					   poly_int64 unadjusted_args_size,
 					   struct args_size *args_size,
 					   unsigned int preferred_unit_stack_boundary)
 {
   /* The number of bytes to pop so that the stack will be
      under-aligned by UNADJUSTED_ARGS_SIZE bytes.  */
-  HOST_WIDE_INT adjustment;
+  poly_int64 adjustment;
   /* The alignment of the stack after the arguments are pushed, if we
      just pushed the arguments without adjust the stack here.  */
   unsigned HOST_WIDE_INT unadjusted_alignment;
 
-  unadjusted_alignment
-    = ((stack_pointer_delta + unadjusted_args_size)
-       % preferred_unit_stack_boundary);
+  if (!known_misalignment (stack_pointer_delta + unadjusted_args_size,
+			   preferred_unit_stack_boundary,
+			   &unadjusted_alignment))
+    return false;
 
   /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
      as possible -- leaving just enough left to cancel out the
@@ -2639,15 +2697,24 @@  combine_pending_stack_adjustment_and_cal
      -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY.  */
 
   /* Begin by trying to pop all the bytes.  */
-  unadjusted_alignment
-    = (unadjusted_alignment
-       - (pending_stack_adjust % preferred_unit_stack_boundary));
+  unsigned HOST_WIDE_INT tmp_misalignment;
+  if (!known_misalignment (pending_stack_adjust,
+			   preferred_unit_stack_boundary,
+			   &tmp_misalignment))
+    return false;
+  unadjusted_alignment -= tmp_misalignment;
   adjustment = pending_stack_adjust;
   /* Push enough additional bytes that the stack will be aligned
      after the arguments are pushed.  */
   if (preferred_unit_stack_boundary > 1 && unadjusted_alignment)
     adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
 
+  /* We need to know whether the adjusted argument size
+     (UNADJUSTED_ARGS_SIZE - ADJUSTMENT) constitutes an allocation
+     or a deallocation.  */
+  if (!ordered_p (adjustment, unadjusted_args_size))
+    return false;
+
   /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
      bytes after the call.  The right number is the entire
      PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
@@ -2655,7 +2722,8 @@  combine_pending_stack_adjustment_and_cal
   args_size->constant
     = pending_stack_adjust - adjustment + unadjusted_args_size;
 
-  return adjustment;
+  *adjustment_out = adjustment;
+  return true;
 }
 
 /* Scan X expression if it does not dereference any argument slots
@@ -2681,8 +2749,8 @@  check_sibcall_argument_overlap_1 (rtx x)
     return 0;
 
   if (code == MEM)
-    return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0),
-						 GET_MODE_SIZE (GET_MODE (x)));
+    return (mem_might_overlap_already_clobbered_arg_p
+	    (XEXP (x, 0), GET_MODE_SIZE (GET_MODE (x))));
 
   /* Scan all subexpressions.  */
   fmt = GET_RTX_FORMAT (code);
@@ -2714,7 +2782,8 @@  check_sibcall_argument_overlap_1 (rtx x)
 check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
 				int mark_stored_args_map)
 {
-  int low, high;
+  poly_uint64 low, high;
+  unsigned HOST_WIDE_INT const_low, const_high;
 
   if (insn == NULL_RTX)
     insn = get_insns ();
@@ -2732,9 +2801,14 @@  check_sibcall_argument_overlap (rtx_insn
 	low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
       else
 	low = arg->locate.slot_offset.constant;
+      high = low + arg->locate.size.constant;
 
-      for (high = low + arg->locate.size.constant; low < high; low++)
-	bitmap_set_bit (stored_args_map, low);
+      const_low = constant_lower_bound (low);
+      if (high.is_constant (&const_high))
+	for (unsigned HOST_WIDE_INT i = const_low; i < const_high; ++i)
+	  bitmap_set_bit (stored_args_map, i);
+      else
+	stored_args_watermark = MIN (stored_args_watermark, const_low);
     }
   return insn != NULL_RTX;
 }
@@ -2877,7 +2951,8 @@  can_implement_as_sibling_call_p (tree ex
      function, we cannot change it into a sibling call.
      crtl->args.pretend_args_size is not part of the
      stack allocated by our caller.  */
-  if (args_size.constant > (crtl->args.size - crtl->args.pretend_args_size))
+  if (may_gt (args_size.constant,
+	      crtl->args.size - crtl->args.pretend_args_size))
     {
       maybe_complain_about_tail_call (exp,
 				      "callee required more stack slots"
@@ -2887,10 +2962,12 @@  can_implement_as_sibling_call_p (tree ex
 
   /* If the callee pops its own arguments, then it must pop exactly
      the same number of arguments as the current function.  */
-  if (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant)
-      != targetm.calls.return_pops_args (current_function_decl,
-					 TREE_TYPE (current_function_decl),
-					 crtl->args.size))
+  if (may_ne (targetm.calls.return_pops_args (fndecl, funtype,
+					      args_size.constant),
+	      targetm.calls.return_pops_args (current_function_decl,
+					      TREE_TYPE
+					      (current_function_decl),
+					      crtl->args.size)))
     {
       maybe_complain_about_tail_call (exp,
 				      "inconsistent number of"
@@ -2980,7 +3057,7 @@  expand_call (tree exp, rtx target, int i
   struct args_size args_size;
   struct args_size adjusted_args_size;
   /* Size of arguments before any adjustments (such as rounding).  */
-  int unadjusted_args_size;
+  poly_int64 unadjusted_args_size;
   /* Data on reg parms scanned so far.  */
   CUMULATIVE_ARGS args_so_far_v;
   cumulative_args_t args_so_far;
@@ -3013,22 +3090,23 @@  expand_call (tree exp, rtx target, int i
   rtx save_area = 0;		/* Place that it is saved */
 #endif
 
-  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
+  unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
   char *initial_stack_usage_map = stack_usage_map;
+  unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
   char *stack_usage_map_buf = NULL;
 
-  int old_stack_allocated;
+  poly_int64 old_stack_allocated;
 
   /* State variables to track stack modifications.  */
   rtx old_stack_level = 0;
   int old_stack_arg_under_construction = 0;
-  int old_pending_adj = 0;
+  poly_int64 old_pending_adj = 0;
   int old_inhibit_defer_pop = inhibit_defer_pop;
 
   /* Some stack pointer alterations we make are performed via
      allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
      which we then also need to save/restore along the way.  */
-  int old_stack_pointer_delta = 0;
+  poly_int64 old_stack_pointer_delta = 0;
 
   rtx call_fusage;
   tree addr = CALL_EXPR_FN (exp);
@@ -3292,7 +3370,8 @@  expand_call (tree exp, rtx target, int i
 	  || reg_mentioned_p (virtual_outgoing_args_rtx,
 			      structure_value_addr))
       && (args_size.var
-	  || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
+	  || (!ACCUMULATE_OUTGOING_ARGS
+	      && maybe_nonzero (args_size.constant))))
     structure_value_addr = copy_to_reg (structure_value_addr);
 
   /* Tail calls can make things harder to debug, and we've traditionally
@@ -3408,10 +3487,10 @@  expand_call (tree exp, rtx target, int i
 	 call sequence.
 	 Also do the adjustments before a throwing call, otherwise
 	 exception handling can fail; PR 19225. */
-      if (pending_stack_adjust >= 32
-	  || (pending_stack_adjust > 0
+      if (may_ge (pending_stack_adjust, 32)
+	  || (maybe_nonzero (pending_stack_adjust)
 	      && (flags & ECF_MAY_BE_ALLOCA))
-	  || (pending_stack_adjust > 0
+	  || (maybe_nonzero (pending_stack_adjust)
 	      && flag_exceptions && !(flags & ECF_NOTHROW))
 	  || pass == 0)
 	do_pending_stack_adjust ();
@@ -3457,8 +3536,10 @@  expand_call (tree exp, rtx target, int i
 	    argblock
 	      = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
 
-	  stored_args_map = sbitmap_alloc (args_size.constant);
+	  HOST_WIDE_INT map_size = constant_lower_bound (args_size.constant);
+	  stored_args_map = sbitmap_alloc (map_size);
 	  bitmap_clear (stored_args_map);
+	  stored_args_watermark = HOST_WIDE_INT_M1U;
 	}
 
       /* If we have no actual push instructions, or shouldn't use them,
@@ -3488,14 +3569,14 @@  expand_call (tree exp, rtx target, int i
 	     in the area reserved for register arguments, which may be part of
 	     the stack frame.  */
 
-	  int needed = adjusted_args_size.constant;
+	  poly_int64 needed = adjusted_args_size.constant;
 
 	  /* Store the maximum argument space used.  It will be pushed by
 	     the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
 	     checking).  */
 
-	  if (needed > crtl->outgoing_args_size)
-	    crtl->outgoing_args_size = needed;
+	  crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
+						  needed);
 
 	  if (must_preallocate)
 	    {
@@ -3521,12 +3602,16 @@  expand_call (tree exp, rtx target, int i
 		  if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
 		    needed += reg_parm_stack_space;
 
+		  poly_int64 limit = needed;
 		  if (ARGS_GROW_DOWNWARD)
-		    highest_outgoing_arg_in_use
-		      = MAX (initial_highest_arg_in_use, needed + 1);
-		  else
-		    highest_outgoing_arg_in_use
-		      = MAX (initial_highest_arg_in_use, needed);
+		    limit += 1;
+
+		  /* For polynomial sizes, this is the maximum possible
+		     size needed for arguments with a constant size
+		     and offset.  */
+		  HOST_WIDE_INT const_limit = constant_lower_bound (limit);
+		  highest_outgoing_arg_in_use
+		    = MAX (initial_highest_arg_in_use, const_limit);
 
 		  free (stack_usage_map_buf);
 		  stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
@@ -3551,23 +3636,25 @@  expand_call (tree exp, rtx target, int i
 		}
 	      else
 		{
-		  if (inhibit_defer_pop == 0)
+		  /* Try to reuse some or all of the pending_stack_adjust
+		     to get this space.  */
+		  if (inhibit_defer_pop == 0
+		      && (combine_pending_stack_adjustment_and_call
+			  (&needed,
+			   unadjusted_args_size,
+			   &adjusted_args_size,
+			   preferred_unit_stack_boundary)))
 		    {
-		      /* Try to reuse some or all of the pending_stack_adjust
-			 to get this space.  */
-		      needed
-			= (combine_pending_stack_adjustment_and_call
-			   (unadjusted_args_size,
-			    &adjusted_args_size,
-			    preferred_unit_stack_boundary));
-
 		      /* combine_pending_stack_adjustment_and_call computes
 			 an adjustment before the arguments are allocated.
 			 Account for them and see whether or not the stack
 			 needs to go up or down.  */
 		      needed = unadjusted_args_size - needed;
 
-		      if (needed < 0)
+		      /* Checked by
+			 combine_pending_stack_adjustment_and_call.  */
+		      gcc_checking_assert (ordered_p (needed, 0));
+		      if (may_lt (needed, 0))
 			{
 			  /* We're releasing stack space.  */
 			  /* ??? We can avoid any adjustment at all if we're
@@ -3584,11 +3671,12 @@  expand_call (tree exp, rtx target, int i
 
 		  /* Special case this because overhead of `push_block' in
 		     this case is non-trivial.  */
-		  if (needed == 0)
+		  if (known_zero (needed))
 		    argblock = virtual_outgoing_args_rtx;
 		  else
 		    {
-		      argblock = push_block (GEN_INT (needed), 0, 0);
+		      rtx needed_rtx = gen_int_mode (needed, Pmode);
+		      argblock = push_block (needed_rtx, 0, 0);
 		      if (ARGS_GROW_DOWNWARD)
 			argblock = plus_constant (Pmode, argblock, needed);
 		    }
@@ -3614,10 +3702,11 @@  expand_call (tree exp, rtx target, int i
 	  if (stack_arg_under_construction)
 	    {
 	      rtx push_size
-		= GEN_INT (adjusted_args_size.constant
-			   + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype
-			   					      : TREE_TYPE (fndecl))) ? 0
-			      : reg_parm_stack_space));
+		= (gen_int_mode
+		   (adjusted_args_size.constant
+		    + (OUTGOING_REG_PARM_STACK_SPACE (!fndecl ? fntype
+						      : TREE_TYPE (fndecl))
+		       ? 0 : reg_parm_stack_space), Pmode));
 	      if (old_stack_level == 0)
 		{
 		  emit_stack_save (SAVE_BLOCK, &old_stack_level);
@@ -3636,6 +3725,7 @@  expand_call (tree exp, rtx target, int i
 		  stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
 		  stack_usage_map = stack_usage_map_buf;
 		  highest_outgoing_arg_in_use = 0;
+		  stack_usage_watermark = HOST_WIDE_INT_M1U;
 		}
 	      /* We can pass TRUE as the 4th argument because we just
 		 saved the stack pointer and will restore it right after
@@ -3671,24 +3761,23 @@  expand_call (tree exp, rtx target, int i
 
       /* Perform stack alignment before the first push (the last arg).  */
       if (argblock == 0
-          && adjusted_args_size.constant > reg_parm_stack_space
-	  && adjusted_args_size.constant != unadjusted_args_size)
+	  && may_gt (adjusted_args_size.constant, reg_parm_stack_space)
+	  && may_ne (adjusted_args_size.constant, unadjusted_args_size))
 	{
 	  /* When the stack adjustment is pending, we get better code
 	     by combining the adjustments.  */
-	  if (pending_stack_adjust
-	      && ! inhibit_defer_pop)
-	    {
-	      pending_stack_adjust
-		= (combine_pending_stack_adjustment_and_call
-		   (unadjusted_args_size,
-		    &adjusted_args_size,
-		    preferred_unit_stack_boundary));
-	      do_pending_stack_adjust ();
-	    }
+	  if (maybe_nonzero (pending_stack_adjust)
+	      && ! inhibit_defer_pop
+	      && (combine_pending_stack_adjustment_and_call
+		  (&pending_stack_adjust,
+		   unadjusted_args_size,
+		   &adjusted_args_size,
+		   preferred_unit_stack_boundary)))
+	    do_pending_stack_adjust ();
 	  else if (argblock == 0)
-	    anti_adjust_stack (GEN_INT (adjusted_args_size.constant
-					- unadjusted_args_size));
+	    anti_adjust_stack (gen_int_mode (adjusted_args_size.constant
+					     - unadjusted_args_size,
+					     Pmode));
 	}
       /* Now that the stack is properly aligned, pops can't safely
 	 be deferred during the evaluation of the arguments.  */
@@ -3702,9 +3791,10 @@  expand_call (tree exp, rtx target, int i
 	  && pass
 	  && adjusted_args_size.var == 0)
 	{
-	  int pushed = adjusted_args_size.constant + pending_stack_adjust;
-	  if (pushed > current_function_pushed_stack_size)
-	    current_function_pushed_stack_size = pushed;
+	  poly_int64 pushed = (adjusted_args_size.constant
+			       + pending_stack_adjust);
+	  current_function_pushed_stack_size
+	    = upper_bound (current_function_pushed_stack_size, pushed);
 	}
 
       funexp = rtx_for_function_call (fndecl, addr);
@@ -3739,7 +3829,7 @@  expand_call (tree exp, rtx target, int i
 
 	      /* We don't allow passing huge (> 2^30 B) arguments
 	         by value.  It would cause an overflow later on.  */
-	      if (adjusted_args_size.constant
+	      if (constant_lower_bound (adjusted_args_size.constant)
 		  >= (1 << (HOST_BITS_PER_INT - 2)))
 	        {
 	          sorry ("passing too large argument on stack");
@@ -3922,7 +4012,8 @@  expand_call (tree exp, rtx target, int i
 
       /* Stack must be properly aligned now.  */
       gcc_assert (!pass
-		  || !(stack_pointer_delta % preferred_unit_stack_boundary));
+		  || multiple_p (stack_pointer_delta,
+				 preferred_unit_stack_boundary));
 
       /* Generate the actual call instruction.  */
       emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
@@ -4150,6 +4241,7 @@  expand_call (tree exp, rtx target, int i
 	  stack_arg_under_construction = old_stack_arg_under_construction;
 	  highest_outgoing_arg_in_use = initial_highest_arg_in_use;
 	  stack_usage_map = initial_stack_usage_map;
+	  stack_usage_watermark = initial_stack_usage_watermark;
 	  sibcall_failure = 1;
 	}
       else if (ACCUMULATE_OUTGOING_ARGS && pass)
@@ -4174,12 +4266,14 @@  expand_call (tree exp, rtx target, int i
 		  emit_move_insn (stack_area, args[i].save_area);
 		else
 		  emit_block_move (stack_area, args[i].save_area,
-				   GEN_INT (args[i].locate.size.constant),
+				   (gen_int_mode
+				    (args[i].locate.size.constant, Pmode)),
 				   BLOCK_OP_CALL_PARM);
 	      }
 
 	  highest_outgoing_arg_in_use = initial_highest_arg_in_use;
 	  stack_usage_map = initial_stack_usage_map;
+	  stack_usage_watermark = initial_stack_usage_watermark;
 	}
 
       /* If this was alloca, record the new stack level.  */
@@ -4222,8 +4316,8 @@  expand_call (tree exp, rtx target, int i
 
 	  /* Verify that we've deallocated all the stack we used.  */
 	  gcc_assert ((flags & ECF_NORETURN)
-		      || (old_stack_allocated
-			  == stack_pointer_delta - pending_stack_adjust));
+		      || must_eq (old_stack_allocated,
+				  stack_pointer_delta - pending_stack_adjust));
 	}
 
       /* If something prevents making this a sibling call,
@@ -4390,7 +4484,7 @@  emit_library_call_value_1 (int retval, r
   int struct_value_size = 0;
   int flags;
   int reg_parm_stack_space = 0;
-  int needed;
+  poly_int64 needed;
   rtx_insn *before_call;
   bool have_push_fusage;
   tree tfom;			/* type_for_mode (outmode, 0) */
@@ -4403,8 +4497,9 @@  emit_library_call_value_1 (int retval, r
 #endif
 
   /* Size of the stack reserved for parameter registers.  */
-  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
+  unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
   char *initial_stack_usage_map = stack_usage_map;
+  unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
   char *stack_usage_map_buf = NULL;
 
   rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
@@ -4636,27 +4731,25 @@  emit_library_call_value_1 (int retval, r
   assemble_external_libcall (fun);
 
   original_args_size = args_size;
-  args_size.constant = (((args_size.constant
-			  + stack_pointer_delta
-			  + STACK_BYTES - 1)
-			  / STACK_BYTES
-			  * STACK_BYTES)
-			 - stack_pointer_delta);
+  args_size.constant = (aligned_upper_bound (args_size.constant
+					     + stack_pointer_delta,
+					     STACK_BYTES)
+			- stack_pointer_delta);
 
-  args_size.constant = MAX (args_size.constant,
-			    reg_parm_stack_space);
+  args_size.constant = upper_bound (args_size.constant,
+				    reg_parm_stack_space);
 
   if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
     args_size.constant -= reg_parm_stack_space;
 
-  if (args_size.constant > crtl->outgoing_args_size)
-    crtl->outgoing_args_size = args_size.constant;
+  crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
+					  args_size.constant);
 
   if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
     {
-      int pushed = args_size.constant + pending_stack_adjust;
-      if (pushed > current_function_pushed_stack_size)
-	current_function_pushed_stack_size = pushed;
+      poly_int64 pushed = args_size.constant + pending_stack_adjust;
+      current_function_pushed_stack_size
+	= upper_bound (current_function_pushed_stack_size, pushed);
     }
 
   if (ACCUMULATE_OUTGOING_ARGS)
@@ -4681,11 +4774,15 @@  emit_library_call_value_1 (int retval, r
       if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
 	needed += reg_parm_stack_space;
 
+      poly_int64 limit = needed;
       if (ARGS_GROW_DOWNWARD)
-	highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
-					   needed + 1);
-      else
-	highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
+	limit += 1;
+
+      /* For polynomial sizes, this is the maximum possible size needed
+	 for arguments with a constant size and offset.  */
+      HOST_WIDE_INT const_limit = constant_lower_bound (limit);
+      highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
+					 const_limit);
 
       stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
       stack_usage_map = stack_usage_map_buf;
@@ -4713,14 +4810,15 @@  emit_library_call_value_1 (int retval, r
   else
     {
       if (!PUSH_ARGS)
-	argblock = push_block (GEN_INT (args_size.constant), 0, 0);
+	argblock = push_block (gen_int_mode (args_size.constant, Pmode), 0, 0);
     }
 
   /* We push args individually in reverse order, perform stack alignment
      before the first push (the last arg).  */
   if (argblock == 0)
-    anti_adjust_stack (GEN_INT (args_size.constant
-				- original_args_size.constant));
+    anti_adjust_stack (gen_int_mode (args_size.constant
+				     - original_args_size.constant,
+				     Pmode));
 
   argnum = nargs - 1;
 
@@ -4760,7 +4858,7 @@  emit_library_call_value_1 (int retval, r
       rtx reg = argvec[argnum].reg;
       int partial = argvec[argnum].partial;
       unsigned int parm_align = argvec[argnum].locate.boundary;
-      int lower_bound = 0, upper_bound = 0, i;
+      poly_int64 lower_bound = 0, upper_bound = 0;
 
       if (! (reg != 0 && partial == 0))
 	{
@@ -4784,18 +4882,11 @@  emit_library_call_value_1 (int retval, r
 		  upper_bound = lower_bound + argvec[argnum].locate.size.constant;
 		}
 
-	      i = lower_bound;
-	      /* Don't worry about things in the fixed argument area;
-		 it has already been saved.  */
-	      if (i < reg_parm_stack_space)
-		i = reg_parm_stack_space;
-	      while (i < upper_bound && stack_usage_map[i] == 0)
-		i++;
-
-	      if (i < upper_bound)
+	      if (stack_region_maybe_used_p (lower_bound, upper_bound,
+					     reg_parm_stack_space))
 		{
 		  /* We need to make a save area.  */
-		  unsigned int size
+		  poly_uint64 size
 		    = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
 		  machine_mode save_mode
 		    = int_mode_for_size (size, 1).else_blk ();
@@ -4815,7 +4906,9 @@  emit_library_call_value_1 (int retval, r
 		      emit_block_move (validize_mem
 				         (copy_rtx (argvec[argnum].save_area)),
 				       stack_area,
-				       GEN_INT (argvec[argnum].locate.size.constant),
+				       (gen_int_mode
+					(argvec[argnum].locate.size.constant,
+					 Pmode)),
 				       BLOCK_OP_CALL_PARM);
 		    }
 		  else
@@ -4829,14 +4922,14 @@  emit_library_call_value_1 (int retval, r
 
 	  emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
 			  partial, reg, 0, argblock,
-			  GEN_INT (argvec[argnum].locate.offset.constant),
+			  (gen_int_mode
+			   (argvec[argnum].locate.offset.constant, Pmode)),
 			  reg_parm_stack_space,
 			  ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad), false);
 
 	  /* Now mark the segment we just used.  */
 	  if (ACCUMULATE_OUTGOING_ARGS)
-	    for (i = lower_bound; i < upper_bound; i++)
-	      stack_usage_map[i] = 1;
+	    mark_stack_region_used (lower_bound, upper_bound);
 
 	  NO_DEFER_POP;
 
@@ -4958,8 +5051,8 @@  emit_library_call_value_1 (int retval, r
 	    ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
 
   /* Stack must be properly aligned now.  */
-  gcc_assert (!(stack_pointer_delta
-		& (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
+  gcc_assert (multiple_p (stack_pointer_delta,
+			  PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT));
 
   before_call = get_last_insn ();
 
@@ -5097,7 +5190,8 @@  emit_library_call_value_1 (int retval, r
 	      emit_block_move (stack_area,
 			       validize_mem
 			         (copy_rtx (argvec[count].save_area)),
-			       GEN_INT (argvec[count].locate.size.constant),
+			       (gen_int_mode
+				(argvec[count].locate.size.constant, Pmode)),
 			       BLOCK_OP_CALL_PARM);
 	    else
 	      emit_move_insn (stack_area, argvec[count].save_area);
@@ -5105,6 +5199,7 @@  emit_library_call_value_1 (int retval, r
 
       highest_outgoing_arg_in_use = initial_highest_arg_in_use;
       stack_usage_map = initial_stack_usage_map;
+      stack_usage_watermark = initial_stack_usage_watermark;
     }
 
   free (stack_usage_map_buf);
@@ -5201,8 +5296,8 @@  store_one_arg (struct arg_data *arg, rtx
   tree pval = arg->tree_value;
   rtx reg = 0;
   int partial = 0;
-  int used = 0;
-  int i, lower_bound = 0, upper_bound = 0;
+  poly_int64 used = 0;
+  poly_int64 lower_bound = 0, upper_bound = 0;
   int sibcall_failure = 0;
 
   if (TREE_CODE (pval) == ERROR_MARK)
@@ -5223,7 +5318,10 @@  store_one_arg (struct arg_data *arg, rtx
 	      /* stack_slot is negative, but we want to index stack_usage_map
 		 with positive values.  */
 	      if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
-		upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
+		{
+		  rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
+		  upper_bound = -rtx_to_poly_int64 (offset) + 1;
+		}
 	      else
 		upper_bound = 0;
 
@@ -5232,25 +5330,21 @@  store_one_arg (struct arg_data *arg, rtx
 	  else
 	    {
 	      if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
-		lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
+		{
+		  rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
+		  lower_bound = rtx_to_poly_int64 (offset);
+		}
 	      else
 		lower_bound = 0;
 
 	      upper_bound = lower_bound + arg->locate.size.constant;
 	    }
 
-	  i = lower_bound;
-	  /* Don't worry about things in the fixed argument area;
-	     it has already been saved.  */
-	  if (i < reg_parm_stack_space)
-	    i = reg_parm_stack_space;
-	  while (i < upper_bound && stack_usage_map[i] == 0)
-	    i++;
-
-	  if (i < upper_bound)
+	  if (stack_region_maybe_used_p (lower_bound, upper_bound,
+					 reg_parm_stack_space))
 	    {
 	      /* We need to make a save area.  */
-	      unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
+	      poly_uint64 size = arg->locate.size.constant * BITS_PER_UNIT;
 	      machine_mode save_mode
 		= int_mode_for_size (size, 1).else_blk ();
 	      rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
@@ -5263,7 +5357,8 @@  store_one_arg (struct arg_data *arg, rtx
 		  preserve_temp_slots (arg->save_area);
 		  emit_block_move (validize_mem (copy_rtx (arg->save_area)),
 				   stack_area,
-				   GEN_INT (arg->locate.size.constant),
+				   (gen_int_mode
+				    (arg->locate.size.constant, Pmode)),
 				   BLOCK_OP_CALL_PARM);
 		}
 	      else
@@ -5340,8 +5435,8 @@  store_one_arg (struct arg_data *arg, rtx
   /* Check for overlap with already clobbered argument area.  */
   if ((flags & ECF_SIBCALL)
       && MEM_P (arg->value)
-      && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0),
-					       arg->locate.size.constant))
+      && mem_might_overlap_already_clobbered_arg_p (XEXP (arg->value, 0),
+						    arg->locate.size.constant))
     sibcall_failure = 1;
 
   /* Don't allow anything left on stack from computation
@@ -5389,12 +5484,10 @@  store_one_arg (struct arg_data *arg, rtx
       if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
 	  == PAD_DOWNWARD)
 	{
-	  int pad = used - size;
-	  if (pad)
-	    {
-	      unsigned int pad_align = least_bit_hwi (pad) * BITS_PER_UNIT;
-	      parm_align = MIN (parm_align, pad_align);
-	    }
+	  poly_int64 pad = used - size;
+	  unsigned int pad_align = known_alignment (pad) * BITS_PER_UNIT;
+	  if (pad_align != 0)
+	    parm_align = MIN (parm_align, pad_align);
 	}
 
       /* This isn't already where we want it on the stack, so put it there.
@@ -5415,7 +5508,7 @@  store_one_arg (struct arg_data *arg, rtx
       /* BLKmode, at least partly to be pushed.  */
 
       unsigned int parm_align;
-      int excess;
+      poly_int64 excess;
       rtx size_rtx;
 
       /* Pushing a nonscalar.
@@ -5451,10 +5544,12 @@  store_one_arg (struct arg_data *arg, rtx
 	{
 	  if (arg->locate.size.var)
 	    parm_align = BITS_PER_UNIT;
-	  else if (excess)
+	  else
 	    {
-	      unsigned int excess_align = least_bit_hwi (excess) * BITS_PER_UNIT;
-	      parm_align = MIN (parm_align, excess_align);
+	      unsigned int excess_align
+		= known_alignment (excess) * BITS_PER_UNIT;
+	      if (excess_align != 0)
+		parm_align = MIN (parm_align, excess_align);
 	    }
 	}
 
@@ -5463,7 +5558,7 @@  store_one_arg (struct arg_data *arg, rtx
 	  /* emit_push_insn might not work properly if arg->value and
 	     argblock + arg->locate.offset areas overlap.  */
 	  rtx x = arg->value;
-	  int i = 0;
+	  poly_int64 i = 0;
 
 	  if (XEXP (x, 0) == crtl->args.internal_arg_pointer
 	      || (GET_CODE (XEXP (x, 0)) == PLUS
@@ -5472,7 +5567,7 @@  store_one_arg (struct arg_data *arg, rtx
 		  && CONST_INT_P (XEXP (XEXP (x, 0), 1))))
 	    {
 	      if (XEXP (x, 0) != crtl->args.internal_arg_pointer)
-		i = INTVAL (XEXP (XEXP (x, 0), 1));
+		i = rtx_to_poly_int64 (XEXP (XEXP (x, 0), 1));
 
 	      /* arg.locate doesn't contain the pretend_args_size offset,
 		 it's part of argblock.  Ensure we don't count it in I.  */
@@ -5483,33 +5578,28 @@  store_one_arg (struct arg_data *arg, rtx
 
 	      /* expand_call should ensure this.  */
 	      gcc_assert (!arg->locate.offset.var
-			  && arg->locate.size.var == 0
-			  && CONST_INT_P (size_rtx));
+			  && arg->locate.size.var == 0);
+	      poly_int64 size_val = rtx_to_poly_int64 (size_rtx);
 
-	      if (arg->locate.offset.constant > i)
-		{
-		  if (arg->locate.offset.constant < i + INTVAL (size_rtx))
-		    sibcall_failure = 1;
-		}
-	      else if (arg->locate.offset.constant < i)
-		{
-		  /* Use arg->locate.size.constant instead of size_rtx
-		     because we only care about the part of the argument
-		     on the stack.  */
-		  if (i < (arg->locate.offset.constant
-			   + arg->locate.size.constant))
-		    sibcall_failure = 1;
-		}
-	      else
+	      if (must_eq (arg->locate.offset.constant, i))
 		{
 		  /* Even though they appear to be at the same location,
 		     if part of the outgoing argument is in registers,
 		     they aren't really at the same location.  Check for
 		     this by making sure that the incoming size is the
 		     same as the outgoing size.  */
-		  if (arg->locate.size.constant != INTVAL (size_rtx))
+		  if (may_ne (arg->locate.size.constant, size_val))
 		    sibcall_failure = 1;
 		}
+	      else if (maybe_in_range_p (arg->locate.offset.constant,
+					 i, size_val))
+		sibcall_failure = 1;
+	      /* Use arg->locate.size.constant instead of size_rtx
+		 because we only care about the part of the argument
+		 on the stack.  */
+	      else if (maybe_in_range_p (i, arg->locate.offset.constant,
+					 arg->locate.size.constant))
+		sibcall_failure = 1;
 	    }
 	}
 
@@ -5541,8 +5631,7 @@  store_one_arg (struct arg_data *arg, rtx
   /* Mark all slots this store used.  */
   if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
       && argblock && ! variable_size && arg->stack)
-    for (i = lower_bound; i < upper_bound; i++)
-      stack_usage_map[i] = 1;
+    mark_stack_region_used (lower_bound, upper_bound);
 
   /* Once we have pushed something, pops can't safely
      be deferred during the rest of the arguments.  */
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	2017-10-23 17:11:40.145755651 +0100
+++ gcc/config/arm/arm.c	2017-10-23 17:19:01.398170131 +0100
@@ -19764,8 +19764,8 @@  arm_output_function_prologue (FILE *f)
   if (IS_CMSE_ENTRY (func_type))
     asm_fprintf (f, "\t%@ Non-secure entry function: called from non-secure code.\n");
 
-  asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %wd\n",
-	       crtl->args.size,
+  asm_fprintf (f, "\t%@ args = %wd, pretend = %d, frame = %wd\n",
+	       (HOST_WIDE_INT) crtl->args.size,
 	       crtl->args.pretend_args_size,
 	       (HOST_WIDE_INT) get_frame_size ());
 
Index: gcc/config/avr/avr.c
===================================================================
--- gcc/config/avr/avr.c	2017-10-23 17:18:53.829515199 +0100
+++ gcc/config/avr/avr.c	2017-10-23 17:19:01.400170158 +0100
@@ -1151,7 +1151,8 @@  avr_accumulate_outgoing_args (void)
 static inline int
 avr_outgoing_args_size (void)
 {
-  return ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0;
+  return (ACCUMULATE_OUTGOING_ARGS
+	  ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0);
 }
 
 
Index: gcc/config/microblaze/microblaze.c
===================================================================
--- gcc/config/microblaze/microblaze.c	2017-10-23 17:11:40.161786287 +0100
+++ gcc/config/microblaze/microblaze.c	2017-10-23 17:19:01.405170225 +0100
@@ -2728,7 +2728,7 @@  microblaze_function_prologue (FILE * fil
 			  STACK_POINTER_REGNUM]), fsiz,
 	       reg_names[MB_ABI_SUB_RETURN_ADDR_REGNUM + GP_REG_FIRST],
 	       current_frame_info.var_size, current_frame_info.num_gp,
-	       crtl->outgoing_args_size);
+	       (int) crtl->outgoing_args_size);
       fprintf (file, "\t.mask\t0x%08lx\n", current_frame_info.mask);
     }
 }
Index: gcc/config/cr16/cr16.c
===================================================================
--- gcc/config/cr16/cr16.c	2017-10-23 17:11:40.148761395 +0100
+++ gcc/config/cr16/cr16.c	2017-10-23 17:19:01.400170158 +0100
@@ -253,10 +253,8 @@  cr16_class_likely_spilled_p (reg_class_t
   return false;
 }
 
-static int
-cr16_return_pops_args (tree fundecl ATTRIBUTE_UNUSED,
-                       tree funtype ATTRIBUTE_UNUSED, 
-		       int size ATTRIBUTE_UNUSED)
+static poly_int64
+cr16_return_pops_args (tree, tree, poly_int64)
 {
   return 0;
 }
@@ -433,9 +431,10 @@  cr16_compute_frame (void)
     padding_locals = stack_alignment - padding_locals;
 
   current_frame_info.var_size += padding_locals;
-  current_frame_info.total_size = current_frame_info.var_size 
-			          + (ACCUMULATE_OUTGOING_ARGS
-			             ? crtl->outgoing_args_size : 0);
+  current_frame_info.total_size
+    = (current_frame_info.var_size
+       + (ACCUMULATE_OUTGOING_ARGS
+	  ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0));
 }
 
 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET.  */
@@ -449,12 +448,14 @@  cr16_initial_elimination_offset (int fro
   cr16_compute_frame ();
 
   if (((from) == FRAME_POINTER_REGNUM) && ((to) == STACK_POINTER_REGNUM))
-    return (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0);
+    return (ACCUMULATE_OUTGOING_ARGS
+	    ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0);
   else if (((from) == ARG_POINTER_REGNUM) && ((to) == FRAME_POINTER_REGNUM))
     return (current_frame_info.reg_size + current_frame_info.var_size);
   else if (((from) == ARG_POINTER_REGNUM) && ((to) == STACK_POINTER_REGNUM))
     return (current_frame_info.reg_size + current_frame_info.var_size 
-	    + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0));
+	    + (ACCUMULATE_OUTGOING_ARGS
+	       ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0));
   else
     gcc_unreachable ();
 }
Index: gcc/config/ft32/ft32.c
===================================================================
--- gcc/config/ft32/ft32.c	2017-10-23 17:11:40.150765225 +0100
+++ gcc/config/ft32/ft32.c	2017-10-23 17:19:01.400170158 +0100
@@ -417,7 +417,8 @@  ft32_compute_frame (void)
   cfun->machine->size_for_adjusting_sp =
     0 // crtl->args.pretend_args_size
     + cfun->machine->local_vars_size
-    + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0);
+    + (ACCUMULATE_OUTGOING_ARGS
+       ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0);
 }
 
 // Must use LINK/UNLINK when...
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	2017-10-23 17:11:40.155774798 +0100
+++ gcc/config/i386/i386.c	2017-10-23 17:19:01.404170211 +0100
@@ -6528,8 +6528,8 @@  ix86_keep_aggregate_return_pointer (tree
 
    The attribute stdcall is equivalent to RTD on a per module basis.  */
 
-static int
-ix86_return_pops_args (tree fundecl, tree funtype, int size)
+static poly_int64
+ix86_return_pops_args (tree fundecl, tree funtype, poly_int64 size)
 {
   unsigned int ccvt;
 
@@ -14172,7 +14172,7 @@  ix86_expand_split_stack_prologue (void)
      anyhow.  In 64-bit mode we pass the parameters in r10 and
      r11.  */
   allocate_rtx = GEN_INT (allocate);
-  args_size = crtl->args.size >= 0 ? crtl->args.size : 0;
+  args_size = crtl->args.size >= 0 ? (HOST_WIDE_INT) crtl->args.size : 0;
   call_fusage = NULL_RTX;
   rtx pop = NULL_RTX;
   if (TARGET_64BIT)
Index: gcc/config/moxie/moxie.c
===================================================================
--- gcc/config/moxie/moxie.c	2017-10-23 17:11:40.164792031 +0100
+++ gcc/config/moxie/moxie.c	2017-10-23 17:19:01.405170225 +0100
@@ -270,7 +270,8 @@  moxie_compute_frame (void)
   cfun->machine->size_for_adjusting_sp = 
     crtl->args.pretend_args_size
     + cfun->machine->local_vars_size 
-    + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0);
+    + (ACCUMULATE_OUTGOING_ARGS
+       ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0);
 }
 
 void
Index: gcc/config/m68k/m68k.c
===================================================================
--- gcc/config/m68k/m68k.c	2017-10-23 17:11:40.160784372 +0100
+++ gcc/config/m68k/m68k.c	2017-10-23 17:19:01.404170211 +0100
@@ -178,7 +178,7 @@  static bool m68k_return_in_memory (const
 #endif
 static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
 static void m68k_trampoline_init (rtx, tree, rtx);
-static int m68k_return_pops_args (tree, tree, int);
+static poly_int64 m68k_return_pops_args (tree, tree, poly_int64);
 static rtx m68k_delegitimize_address (rtx);
 static void m68k_function_arg_advance (cumulative_args_t, machine_mode,
 				       const_tree, bool);
@@ -6533,14 +6533,14 @@  m68k_trampoline_init (rtx m_tramp, tree
    standard Unix calling sequences.  If the option is not selected,
    the caller must always pop the args.  */
 
-static int
-m68k_return_pops_args (tree fundecl, tree funtype, int size)
+static poly_int64
+m68k_return_pops_args (tree fundecl, tree funtype, poly_int64 size)
 {
   return ((TARGET_RTD
 	   && (!fundecl
 	       || TREE_CODE (fundecl) != IDENTIFIER_NODE)
 	   && (!stdarg_p (funtype)))
-	  ? size : 0);
+	  ? (HOST_WIDE_INT) size : 0);
 }
 
 /* Make sure everything's fine if we *don't* have a given processor.
Index: gcc/config/vax/vax.c
===================================================================
--- gcc/config/vax/vax.c	2017-10-23 17:11:40.188837984 +0100
+++ gcc/config/vax/vax.c	2017-10-23 17:19:01.407170251 +0100
@@ -62,7 +62,7 @@  static rtx vax_struct_value_rtx (tree, i
 static rtx vax_builtin_setjmp_frame_value (void);
 static void vax_asm_trampoline_template (FILE *);
 static void vax_trampoline_init (rtx, tree, rtx);
-static int vax_return_pops_args (tree, tree, int);
+static poly_int64 vax_return_pops_args (tree, tree, poly_int64);
 static bool vax_mode_dependent_address_p (const_rtx, addr_space_t);
 
 /* Initialize the GCC target structure.  */
@@ -2136,11 +2136,11 @@  vax_trampoline_init (rtx m_tramp, tree f
 
    On the VAX, the RET insn pops a maximum of 255 args for any function.  */
 
-static int
+static poly_int64
 vax_return_pops_args (tree fundecl ATTRIBUTE_UNUSED,
-		      tree funtype ATTRIBUTE_UNUSED, int size)
+		      tree funtype ATTRIBUTE_UNUSED, poly_int64 size)
 {
-  return size > 255 * 4 ? 0 : size;
+  return size > 255 * 4 ? 0 : (HOST_WIDE_INT) size;
 }
 
 /* Define where to put the arguments to a function.
Index: gcc/config/pa/pa.h
===================================================================
--- gcc/config/pa/pa.h	2017-10-23 17:18:53.830515111 +0100
+++ gcc/config/pa/pa.h	2017-10-23 17:19:01.405170225 +0100
@@ -546,7 +546,7 @@  #define ACCUMULATE_OUTGOING_ARGS 1
    marker, although the runtime documentation only describes a 16
    byte marker.  For compatibility, we allocate 48 bytes.  */
 #define STACK_POINTER_OFFSET \
-  (TARGET_64BIT ? -(crtl->outgoing_args_size + 48): -32)
+  (TARGET_64BIT ? -(crtl->outgoing_args_size + 48) : poly_int64 (-32))
 
 #define STACK_DYNAMIC_OFFSET(FNDECL)	\
   (TARGET_64BIT				\
@@ -703,7 +703,7 @@  #define NO_PROFILE_COUNTERS 1
 
 #define EXIT_IGNORE_STACK	\
  (maybe_nonzero (get_frame_size ())	\
-  || cfun->calls_alloca || crtl->outgoing_args_size)
+  || cfun->calls_alloca || maybe_nonzero (crtl->outgoing_args_size))
 
 /* Length in units of the trampoline for entering a nested function.  */
 
Index: gcc/config/arm/arm.h
===================================================================
--- gcc/config/arm/arm.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/arm/arm.h	2017-10-23 17:19:01.399170145 +0100
@@ -1248,7 +1248,7 @@  #define FRAME_GROWS_DOWNWARD 1
    couldn't convert a direct call into an indirect one.  */
 #define CALLER_INTERWORKING_SLOT_SIZE			\
   (TARGET_CALLER_INTERWORKING				\
-   && crtl->outgoing_args_size != 0		\
+   && maybe_nonzero (crtl->outgoing_args_size)		\
    ? UNITS_PER_WORD : 0)
 
 /* Offset within stack frame to start allocating local variables at.
Index: gcc/config/powerpcspe/aix.h
===================================================================
--- gcc/config/powerpcspe/aix.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/powerpcspe/aix.h	2017-10-23 17:19:01.405170225 +0100
@@ -73,7 +73,8 @@  #define STARTING_FRAME_OFFSET						\
    `emit-rtl.c').  */
 #undef STACK_DYNAMIC_OFFSET
 #define STACK_DYNAMIC_OFFSET(FUNDECL)					\
-   RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET, 16)
+  RS6000_ALIGN (crtl->outgoing_args_size.to_constant () \
+		+ STACK_POINTER_OFFSET, 16)
 
 #undef  TARGET_IEEEQUAD
 #define TARGET_IEEEQUAD 0
Index: gcc/config/powerpcspe/darwin.h
===================================================================
--- gcc/config/powerpcspe/darwin.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/powerpcspe/darwin.h	2017-10-23 17:19:01.405170225 +0100
@@ -157,7 +157,7 @@  #define STARTING_FRAME_OFFSET						\
 
 #undef STACK_DYNAMIC_OFFSET
 #define STACK_DYNAMIC_OFFSET(FUNDECL)					\
-  (RS6000_ALIGN (crtl->outgoing_args_size, 16)		\
+  (RS6000_ALIGN (crtl->outgoing_args_size.to_constant (), 16)		\
    + (STACK_POINTER_OFFSET))
 
 /* Darwin uses a function call if everything needs to be saved/restored.  */
Index: gcc/config/powerpcspe/powerpcspe.h
===================================================================
--- gcc/config/powerpcspe/powerpcspe.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/powerpcspe/powerpcspe.h	2017-10-23 17:19:01.406170238 +0100
@@ -1668,7 +1668,8 @@  #define STARTING_FRAME_OFFSET						\
    This value must be a multiple of STACK_BOUNDARY (hard coded in
    `emit-rtl.c').  */
 #define STACK_DYNAMIC_OFFSET(FUNDECL)					\
-  RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET,	\
+  RS6000_ALIGN (crtl->outgoing_args_size.to_constant ()			\
+		+ STACK_POINTER_OFFSET,					\
 		(TARGET_ALTIVEC || TARGET_VSX) ? 16 : 8)
 
 /* If we generate an insn to push BYTES bytes,
Index: gcc/config/rs6000/aix.h
===================================================================
--- gcc/config/rs6000/aix.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/rs6000/aix.h	2017-10-23 17:19:01.406170238 +0100
@@ -73,7 +73,8 @@  #define STARTING_FRAME_OFFSET						\
    `emit-rtl.c').  */
 #undef STACK_DYNAMIC_OFFSET
 #define STACK_DYNAMIC_OFFSET(FUNDECL)					\
-   RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET, 16)
+   RS6000_ALIGN (crtl->outgoing_args_size.to_constant ()		\
+		 + STACK_POINTER_OFFSET, 16)
 
 #undef  TARGET_IEEEQUAD
 #define TARGET_IEEEQUAD 0
Index: gcc/config/rs6000/darwin.h
===================================================================
--- gcc/config/rs6000/darwin.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/rs6000/darwin.h	2017-10-23 17:19:01.406170238 +0100
@@ -157,7 +157,7 @@  #define STARTING_FRAME_OFFSET						\
 
 #undef STACK_DYNAMIC_OFFSET
 #define STACK_DYNAMIC_OFFSET(FUNDECL)					\
-  (RS6000_ALIGN (crtl->outgoing_args_size, 16)		\
+  (RS6000_ALIGN (crtl->outgoing_args_size.to_constant (), 16)		\
    + (STACK_POINTER_OFFSET))
 
 /* Darwin uses a function call if everything needs to be saved/restored.  */
Index: gcc/config/rs6000/rs6000.h
===================================================================
--- gcc/config/rs6000/rs6000.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/config/rs6000/rs6000.h	2017-10-23 17:19:01.407170251 +0100
@@ -1570,7 +1570,8 @@  #define STARTING_FRAME_OFFSET						\
    This value must be a multiple of STACK_BOUNDARY (hard coded in
    `emit-rtl.c').  */
 #define STACK_DYNAMIC_OFFSET(FUNDECL)					\
-  RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET,	\
+  RS6000_ALIGN (crtl->outgoing_args_size.to_constant ()			\
+		+ STACK_POINTER_OFFSET,					\
 		(TARGET_ALTIVEC || TARGET_VSX) ? 16 : 8)
 
 /* If we generate an insn to push BYTES bytes,
Index: gcc/dojump.h
===================================================================
--- gcc/dojump.h	2017-10-23 16:52:18.296738218 +0100
+++ gcc/dojump.h	2017-10-23 17:19:01.409170278 +0100
@@ -40,10 +40,10 @@  extern void do_pending_stack_adjust (voi
 struct saved_pending_stack_adjust
 {
   /* Saved value of pending_stack_adjust.  */
-  int x_pending_stack_adjust;
+  poly_int64 x_pending_stack_adjust;
 
   /* Saved value of stack_pointer_delta.  */
-  int x_stack_pointer_delta;
+  poly_int64 x_stack_pointer_delta;
 };
 
 /* Remember pending_stack_adjust/stack_pointer_delta.
Index: gcc/dojump.c
===================================================================
--- gcc/dojump.c	2017-10-23 16:52:18.296738218 +0100
+++ gcc/dojump.c	2017-10-23 17:19:01.409170278 +0100
@@ -89,8 +89,8 @@  do_pending_stack_adjust (void)
 {
   if (inhibit_defer_pop == 0)
     {
-      if (pending_stack_adjust != 0)
-        adjust_stack (GEN_INT (pending_stack_adjust));
+      if (maybe_nonzero (pending_stack_adjust))
+	adjust_stack (gen_int_mode (pending_stack_adjust, Pmode));
       pending_stack_adjust = 0;
     }
 }
Index: gcc/explow.c
===================================================================
--- gcc/explow.c	2017-10-23 17:18:57.859160965 +0100
+++ gcc/explow.c	2017-10-23 17:19:01.409170278 +0100
@@ -1467,8 +1467,8 @@  allocate_dynamic_stack_space (rtx size,
 
  /* We ought to be called always on the toplevel and stack ought to be aligned
     properly.  */
-  gcc_assert (!(stack_pointer_delta
-		% (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)));
+  gcc_assert (multiple_p (stack_pointer_delta,
+			  PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT));
 
   /* If needed, check that we have the required amount of stack.  Take into
      account what has already been checked.  */
@@ -1498,7 +1498,7 @@  allocate_dynamic_stack_space (rtx size,
     }
   else
     {
-      int saved_stack_pointer_delta;
+      poly_int64 saved_stack_pointer_delta;
 
       if (!STACK_GROWS_DOWNWARD)
 	emit_move_insn (target, virtual_stack_dynamic_rtx);
Index: gcc/function.c
===================================================================
--- gcc/function.c	2017-10-23 17:18:59.743148042 +0100
+++ gcc/function.c	2017-10-23 17:19:01.410170292 +0100
@@ -1407,7 +1407,7 @@  #define STACK_DYNAMIC_OFFSET(FNDECL)	\
   : 0) + (STACK_POINTER_OFFSET))
 #else
 #define STACK_DYNAMIC_OFFSET(FNDECL)	\
-((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0)	      \
+  ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : poly_int64 (0)) \
  + (STACK_POINTER_OFFSET))
 #endif
 #endif
@@ -2720,12 +2720,15 @@  assign_parm_find_stack_rtl (tree parm, s
      is TARGET_FUNCTION_ARG_BOUNDARY.  If we're using slot_offset, we're
      intentionally forcing upward padding.  Otherwise we have to come
      up with a guess at the alignment based on OFFSET_RTX.  */
+  poly_int64 offset;
   if (data->locate.where_pad != PAD_DOWNWARD || data->entry_parm)
     align = boundary;
-  else if (CONST_INT_P (offset_rtx))
+  else if (poly_int_rtx_p (offset_rtx, &offset))
     {
-      align = INTVAL (offset_rtx) * BITS_PER_UNIT | boundary;
-      align = least_bit_hwi (align);
+      align = least_bit_hwi (boundary);
+      unsigned int offset_align = known_alignment (offset) * BITS_PER_UNIT;
+      if (offset_align != 0)
+	align = MIN (align, offset_align);
     }
   set_mem_align (stack_parm, align);
 
@@ -3887,14 +3890,15 @@  assign_parms (tree fndecl)
   /* Adjust function incoming argument size for alignment and
      minimum length.  */
 
-  crtl->args.size = MAX (crtl->args.size, all.reg_parm_stack_space);
-  crtl->args.size = CEIL_ROUND (crtl->args.size,
-					   PARM_BOUNDARY / BITS_PER_UNIT);
+  crtl->args.size = upper_bound (crtl->args.size, all.reg_parm_stack_space);
+  crtl->args.size = aligned_upper_bound (crtl->args.size,
+					 PARM_BOUNDARY / BITS_PER_UNIT);
 
   if (ARGS_GROW_DOWNWARD)
     {
       crtl->args.arg_offset_rtx
-	= (all.stack_args_size.var == 0 ? GEN_INT (-all.stack_args_size.constant)
+	= (all.stack_args_size.var == 0
+	   ? gen_int_mode (-all.stack_args_size.constant, Pmode)
 	   : expand_expr (size_diffop (all.stack_args_size.var,
 				       size_int (-all.stack_args_size.constant)),
 			  NULL_RTX, VOIDmode, EXPAND_NORMAL));
@@ -4135,15 +4139,19 @@  locate_and_pad_parm (machine_mode passed
     {
       if (reg_parm_stack_space > 0)
 	{
-	  if (initial_offset_ptr->var)
+	  if (initial_offset_ptr->var
+	      || !ordered_p (initial_offset_ptr->constant,
+			     reg_parm_stack_space))
 	    {
 	      initial_offset_ptr->var
 		= size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
 			      ssize_int (reg_parm_stack_space));
 	      initial_offset_ptr->constant = 0;
 	    }
-	  else if (initial_offset_ptr->constant < reg_parm_stack_space)
-	    initial_offset_ptr->constant = reg_parm_stack_space;
+	  else
+	    initial_offset_ptr->constant
+	      = ordered_max (initial_offset_ptr->constant,
+			     reg_parm_stack_space);
 	}
     }
 
@@ -4269,9 +4277,9 @@  pad_to_arg_alignment (struct args_size *
 		      struct args_size *alignment_pad)
 {
   tree save_var = NULL_TREE;
-  HOST_WIDE_INT save_constant = 0;
+  poly_int64 save_constant = 0;
   int boundary_in_bytes = boundary / BITS_PER_UNIT;
-  HOST_WIDE_INT sp_offset = STACK_POINTER_OFFSET;
+  poly_int64 sp_offset = STACK_POINTER_OFFSET;
 
 #ifdef SPARC_STACK_BOUNDARY_HACK
   /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
@@ -4292,7 +4300,10 @@  pad_to_arg_alignment (struct args_size *
 
   if (boundary > BITS_PER_UNIT)
     {
-      if (offset_ptr->var)
+      int misalign;
+      if (offset_ptr->var
+	  || !known_misalignment (offset_ptr->constant + sp_offset,
+				  boundary_in_bytes, &misalign))
 	{
 	  tree sp_offset_tree = ssize_int (sp_offset);
 	  tree offset = size_binop (PLUS_EXPR,
@@ -4313,13 +4324,13 @@  pad_to_arg_alignment (struct args_size *
 	}
       else
 	{
-	  offset_ptr->constant = -sp_offset +
-	    (ARGS_GROW_DOWNWARD
-	    ? FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes)
-	    : CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes));
+	  if (ARGS_GROW_DOWNWARD)
+	    offset_ptr->constant -= misalign;
+	  else
+	    offset_ptr->constant += -misalign & (boundary_in_bytes - 1);
 
-	    if (boundary > PARM_BOUNDARY)
-	      alignment_pad->constant = offset_ptr->constant - save_constant;
+	  if (boundary > PARM_BOUNDARY)
+	    alignment_pad->constant = offset_ptr->constant - save_constant;
 	}
     }
 }
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c	2017-10-23 16:52:18.296738218 +0100
+++ gcc/toplev.c	2017-10-23 17:19:01.412170318 +0100
@@ -958,19 +958,32 @@  output_stack_usage (void)
   stack_usage_kind = STATIC;
 
   /* Add the maximum amount of space pushed onto the stack.  */
-  if (current_function_pushed_stack_size > 0)
+  if (maybe_nonzero (current_function_pushed_stack_size))
     {
-      stack_usage += current_function_pushed_stack_size;
-      stack_usage_kind = DYNAMIC_BOUNDED;
+      HOST_WIDE_INT extra;
+      if (current_function_pushed_stack_size.is_constant (&extra))
+	{
+	  stack_usage += extra;
+	  stack_usage_kind = DYNAMIC_BOUNDED;
+	}
+      else
+	{
+	  extra = constant_lower_bound (current_function_pushed_stack_size);
+	  stack_usage += extra;
+	  stack_usage_kind = DYNAMIC;
+	}
     }
 
   /* Now on to the tricky part: dynamic stack allocation.  */
   if (current_function_allocates_dynamic_stack_space)
     {
-      if (current_function_has_unbounded_dynamic_stack_size)
-	stack_usage_kind = DYNAMIC;
-      else
-	stack_usage_kind = DYNAMIC_BOUNDED;
+      if (stack_usage_kind != DYNAMIC)
+	{
+	  if (current_function_has_unbounded_dynamic_stack_size)
+	    stack_usage_kind = DYNAMIC;
+	  else
+	    stack_usage_kind = DYNAMIC_BOUNDED;
+	}
 
       /* Add the size even in the unbounded case, this can't hurt.  */
       stack_usage += current_function_dynamic_stack_size;