]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cfgexpand.c
Come up with fndecl_built_in_p.
[thirdparty/gcc.git] / gcc / cfgexpand.c
index f6e306e35fb1d49b8580854efd31f77f9916e1ec..2d3111da25d917256f21a66736cbdbb38a6f79ea 100644 (file)
@@ -1,5 +1,5 @@
 /* A pass for lowering trees to RTL.
-   Copyright (C) 2004-2017 Free Software Foundation, Inc.
+   Copyright (C) 2004-2018 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -74,8 +74,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-address.h"
 #include "output.h"
 #include "builtins.h"
-#include "tree-chkp.h"
-#include "rtl-chkp.h"
 
 /* Some systems use __main in a way incompatible with its use in gcc, in these
    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
@@ -314,7 +312,7 @@ struct stack_var
 
   /* Initially, the size of the variable.  Later, the size of the partition,
      if this variable becomes it's partition's representative.  */
-  HOST_WIDE_INT size;
+  poly_uint64 size;
 
   /* The *byte* alignment required for this variable.  Or as, with the
      size, the alignment for this partition.  */
@@ -389,22 +387,23 @@ align_base (HOST_WIDE_INT base, unsigned HOST_WIDE_INT align, bool align_up)
 /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
    Return the frame offset.  */
 
-static HOST_WIDE_INT
-alloc_stack_frame_space (HOST_WIDE_INT size, unsigned HOST_WIDE_INT align)
+static poly_int64
+alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align)
 {
-  HOST_WIDE_INT offset, new_frame_offset;
+  poly_int64 offset, new_frame_offset;
 
   if (FRAME_GROWS_DOWNWARD)
     {
       new_frame_offset
-       = align_base (frame_offset - frame_phase - size,
-                     align, false) + frame_phase;
+       = aligned_lower_bound (frame_offset - frame_phase - size,
+                              align) + frame_phase;
       offset = new_frame_offset;
     }
   else
     {
       new_frame_offset
-       = align_base (frame_offset - frame_phase, align, true) + frame_phase;
+       = aligned_upper_bound (frame_offset - frame_phase,
+                              align) + frame_phase;
       offset = new_frame_offset;
       new_frame_offset += size;
     }
@@ -442,10 +441,10 @@ add_stack_var (tree decl)
   tree size = TREE_CODE (decl) == SSA_NAME
     ? TYPE_SIZE_UNIT (TREE_TYPE (decl))
     : DECL_SIZE_UNIT (decl);
-  v->size = tree_to_uhwi (size);
+  v->size = tree_to_poly_uint64 (size);
   /* Ensure that all variables have size, so that &a != &b for any two
      variables that are simultaneously live.  */
-  if (v->size == 0)
+  if (known_eq (v->size, 0U))
     v->size = 1;
   v->alignb = align_local_variable (decl);
   /* An alignment of zero can mightily confuse us later.  */
@@ -675,8 +674,8 @@ stack_var_cmp (const void *a, const void *b)
   size_t ib = *(const size_t *)b;
   unsigned int aligna = stack_vars[ia].alignb;
   unsigned int alignb = stack_vars[ib].alignb;
-  HOST_WIDE_INT sizea = stack_vars[ia].size;
-  HOST_WIDE_INT sizeb = stack_vars[ib].size;
+  poly_int64 sizea = stack_vars[ia].size;
+  poly_int64 sizeb = stack_vars[ib].size;
   tree decla = stack_vars[ia].decl;
   tree declb = stack_vars[ib].decl;
   bool largea, largeb;
@@ -689,10 +688,9 @@ stack_var_cmp (const void *a, const void *b)
     return (int)largeb - (int)largea;
 
   /* Secondary compare on size, decreasing  */
-  if (sizea > sizeb)
-    return -1;
-  if (sizea < sizeb)
-    return 1;
+  int diff = compare_sizes_for_sort (sizeb, sizea);
+  if (diff != 0)
+    return diff;
 
   /* Tertiary compare on true alignment, decreasing.  */
   if (aligna < alignb)
@@ -903,7 +901,7 @@ partition_stack_vars (void)
     {
       size_t i = stack_vars_sorted[si];
       unsigned int ialign = stack_vars[i].alignb;
-      HOST_WIDE_INT isize = stack_vars[i].size;
+      poly_int64 isize = stack_vars[i].size;
 
       /* Ignore objects that aren't partition representatives. If we
          see a var that is not a partition representative, it must
@@ -915,7 +913,7 @@ partition_stack_vars (void)
        {
          size_t j = stack_vars_sorted[sj];
          unsigned int jalign = stack_vars[j].alignb;
-         HOST_WIDE_INT jsize = stack_vars[j].size;
+         poly_int64 jsize = stack_vars[j].size;
 
          /* Ignore objects that aren't partition representatives.  */
          if (stack_vars[j].representative != j)
@@ -931,8 +929,8 @@ partition_stack_vars (void)
             sizes, as the shorter vars wouldn't be adequately protected.
             Don't do that for "large" (unsupported) alignment objects,
             those aren't protected anyway.  */
-         if ((asan_sanitize_stack_p ())
-             && isize != jsize
+         if (asan_sanitize_stack_p ()
+             && maybe_ne (isize, jsize)
              && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
            break;
 
@@ -963,9 +961,9 @@ dump_stack_var_partition (void)
       if (stack_vars[i].representative != i)
        continue;
 
-      fprintf (dump_file, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC
-              " align %u\n", (unsigned long) i, stack_vars[i].size,
-              stack_vars[i].alignb);
+      fprintf (dump_file, "Partition %lu: size ", (unsigned long) i);
+      print_dec (stack_vars[i].size, dump_file);
+      fprintf (dump_file, " align %u\n", stack_vars[i].alignb);
 
       for (j = i; j != EOC; j = stack_vars[j].next)
        {
@@ -980,13 +978,13 @@ dump_stack_var_partition (void)
 
 static void
 expand_one_stack_var_at (tree decl, rtx base, unsigned base_align,
-                        HOST_WIDE_INT offset)
+                        poly_int64 offset)
 {
   unsigned align;
   rtx x;
 
   /* If this fails, we've overflowed the stack frame.  Error nicely?  */
-  gcc_assert (offset == trunc_int_for_mode (offset, Pmode));
+  gcc_assert (known_eq (offset, trunc_int_for_mode (offset, Pmode)));
 
   x = plus_constant (Pmode, base, offset);
   x = gen_rtx_MEM (TREE_CODE (decl) == SSA_NAME
@@ -1000,7 +998,7 @@ expand_one_stack_var_at (tree decl, rtx base, unsigned base_align,
         important, we'll simply use the alignment that is already set.  */
       if (base == virtual_stack_vars_rtx)
        offset -= frame_phase;
-      align = least_bit_hwi (offset);
+      align = known_alignment (offset);
       align *= BITS_PER_UNIT;
       if (align == 0 || align > base_align)
        align = base_align;
@@ -1041,7 +1039,7 @@ static void
 expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
 {
   size_t si, i, j, n = stack_vars_num;
-  HOST_WIDE_INT large_size = 0, large_alloc = 0;
+  poly_uint64 large_size = 0, large_alloc = 0;
   rtx large_base = NULL;
   unsigned large_align = 0;
   bool large_allocation_done = false;
@@ -1084,8 +1082,7 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
              : DECL_RTL (decl) != pc_rtx)
            continue;
 
-         large_size += alignb - 1;
-         large_size &= -(HOST_WIDE_INT)alignb;
+         large_size = aligned_upper_bound (large_size, alignb);
          large_size += stack_vars[i].size;
        }
     }
@@ -1094,7 +1091,7 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
     {
       rtx base;
       unsigned base_align, alignb;
-      HOST_WIDE_INT offset;
+      poly_int64 offset;
 
       i = stack_vars_sorted[si];
 
@@ -1119,13 +1116,17 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
       if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
        {
          base = virtual_stack_vars_rtx;
-         if ((asan_sanitize_stack_p ())
-             && pred)
+         /* ASAN description strings don't yet have a syntax for expressing
+            polynomial offsets.  */
+         HOST_WIDE_INT prev_offset;
+         if (asan_sanitize_stack_p ()
+             && pred
+             && frame_offset.is_constant (&prev_offset)
+             && stack_vars[i].size.is_constant ())
            {
-             HOST_WIDE_INT prev_offset
-               = align_base (frame_offset,
-                             MAX (alignb, ASAN_RED_ZONE_SIZE),
-                             !FRAME_GROWS_DOWNWARD);
+             prev_offset = align_base (prev_offset,
+                                       MAX (alignb, ASAN_RED_ZONE_SIZE),
+                                       !FRAME_GROWS_DOWNWARD);
              tree repr_decl = NULL_TREE;
              offset
                = alloc_stack_frame_space (stack_vars[i].size
@@ -1133,7 +1134,10 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
                                           MAX (alignb, ASAN_RED_ZONE_SIZE));
 
              data->asan_vec.safe_push (prev_offset);
-             data->asan_vec.safe_push (offset + stack_vars[i].size);
+             /* Allocating a constant amount of space from a constant
+                starting offset must give a constant result.  */
+             data->asan_vec.safe_push ((offset + stack_vars[i].size)
+                                       .to_constant ());
              /* Find best representative of the partition.
                 Prefer those with DECL_NAME, even better
                 satisfying asan_protect_stack_decl predicate.  */
@@ -1177,23 +1181,22 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
 
          /* If there were any variables requiring "large" alignment, allocate
             space.  */
-         if (large_size > 0 && ! large_allocation_done)
+         if (maybe_ne (large_size, 0U) && ! large_allocation_done)
            {
-             HOST_WIDE_INT loffset;
+             poly_int64 loffset;
              rtx large_allocsize;
 
-             large_allocsize = GEN_INT (large_size);
+             large_allocsize = gen_int_mode (large_size, Pmode);
              get_dynamic_stack_size (&large_allocsize, 0, large_align, NULL);
              loffset = alloc_stack_frame_space
-               (INTVAL (large_allocsize),
+               (rtx_to_poly_int64 (large_allocsize),
                 PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT);
              large_base = get_dynamic_stack_base (loffset, large_align);
              large_allocation_done = true;
            }
          gcc_assert (large_base != NULL);
 
-         large_alloc += alignb - 1;
-         large_alloc &= -(HOST_WIDE_INT)alignb;
+         large_alloc = aligned_upper_bound (large_alloc, alignb);
          offset = large_alloc;
          large_alloc += stack_vars[i].size;
 
@@ -1211,15 +1214,15 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
        }
     }
 
-  gcc_assert (large_alloc == large_size);
+  gcc_assert (known_eq (large_alloc, large_size));
 }
 
 /* Take into account all sizes of partitions and reset DECL_RTLs.  */
-static HOST_WIDE_INT
+static poly_uint64
 account_stack_vars (void)
 {
   size_t si, j, i, n = stack_vars_num;
-  HOST_WIDE_INT size = 0;
+  poly_uint64 size = 0;
 
   for (si = 0; si < n; ++si)
     {
@@ -1254,10 +1257,10 @@ set_parm_rtl (tree parm, rtx x)
         allocate it, which means that in-frame portion is just a
         pointer.  ??? We've got a pseudo for sure here, do we
         actually dynamically allocate its spilling area if needed?
-        ??? Isn't it a problem when POINTER_SIZE also exceeds
-        MAX_SUPPORTED_STACK_ALIGNMENT, as on cris and lm32?  */
+        ??? Isn't it a problem when Pmode alignment also exceeds
+        MAX_SUPPORTED_STACK_ALIGNMENT, as can happen on cris and lm32?  */
       if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
-       align = POINTER_SIZE;
+       align = GET_MODE_ALIGNMENT (Pmode);
 
       record_alignment_for_reg_var (align);
     }
@@ -1282,18 +1285,19 @@ set_parm_rtl (tree parm, rtx x)
 static void
 expand_one_stack_var_1 (tree var)
 {
-  HOST_WIDE_INT size, offset;
+  poly_uint64 size;
+  poly_int64 offset;
   unsigned byte_align;
 
   if (TREE_CODE (var) == SSA_NAME)
     {
       tree type = TREE_TYPE (var);
-      size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
+      size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
       byte_align = TYPE_ALIGN_UNIT (type);
     }
   else
     {
-      size = tree_to_uhwi (DECL_SIZE_UNIT (var));
+      size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var));
       byte_align = align_local_variable (var);
     }
 
@@ -1377,7 +1381,7 @@ expand_one_ssa_partition (tree var)
   /* If the variable alignment is very large we'll dynamicaly allocate
      it, which means that in-frame portion is just a pointer.  */
   if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
-    align = POINTER_SIZE;
+    align = GET_MODE_ALIGNMENT (Pmode);
 
   record_alignment_for_reg_var (align);
 
@@ -1391,10 +1395,18 @@ expand_one_ssa_partition (tree var)
     }
 
   machine_mode reg_mode = promote_ssa_mode (var, NULL);
-
   rtx x = gen_reg_rtx (reg_mode);
 
   set_rtl (var, x);
+
+  /* For a promoted variable, X will not be used directly but wrapped in a
+     SUBREG with SUBREG_PROMOTED_VAR_P set, which means that the RTL land
+     will assume that its upper bits can be inferred from its lower bits.
+     Therefore, if X isn't initialized on every path from the entry, then
+     we must do it manually in order to fulfill the above assumption.  */
+  if (reg_mode != TYPE_MODE (TREE_TYPE (var))
+      && bitmap_bit_p (SA.partitions_for_undefined_values, part))
+    emit_move_insn (x, CONST0_RTX (reg_mode));
 }
 
 /* Record the association between the RTL generated for partition PART
@@ -1497,12 +1509,14 @@ defer_stack_allocation (tree var, bool toplevel)
   tree size_unit = TREE_CODE (var) == SSA_NAME
     ? TYPE_SIZE_UNIT (TREE_TYPE (var))
     : DECL_SIZE_UNIT (var);
+  poly_uint64 size;
 
   /* Whether the variable is small enough for immediate allocation not to be
      a problem with regard to the frame size.  */
   bool smallish
-    = ((HOST_WIDE_INT) tree_to_uhwi (size_unit)
-       < PARAM_VALUE (PARAM_MIN_SIZE_FOR_STACK_SHARING));
+    = (poly_int_tree_p (size_unit, &size)
+       && (estimated_poly_value (size)
+          < PARAM_VALUE (PARAM_MIN_SIZE_FOR_STACK_SHARING)));
 
   /* If stack protection is enabled, *all* stack variables must be deferred,
      so that we can re-order the strings to the top of the frame.
@@ -1556,7 +1570,7 @@ defer_stack_allocation (tree var, bool toplevel)
    Return stack usage this variable is supposed to take.
 */
 
-static HOST_WIDE_INT
+static poly_uint64
 expand_one_var (tree var, bool toplevel, bool really_expand)
 {
   unsigned int align = BITS_PER_UNIT;
@@ -1594,11 +1608,12 @@ expand_one_var (tree var, bool toplevel, bool really_expand)
       /* If the variable alignment is very large we'll dynamicaly allocate
         it, which means that in-frame portion is just a pointer.  */
       if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
-       align = POINTER_SIZE;
+       align = GET_MODE_ALIGNMENT (Pmode);
     }
 
   record_alignment_for_reg_var (align);
 
+  poly_uint64 size;
   if (TREE_CODE (origvar) == SSA_NAME)
     {
       gcc_assert (!VAR_P (var)
@@ -1639,7 +1654,8 @@ expand_one_var (tree var, bool toplevel, bool really_expand)
       if (really_expand)
         expand_one_register_var (origvar);
     }
-  else if (! valid_constant_size_p (DECL_SIZE_UNIT (var)))
+  else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size)
+          || !valid_constant_size_p (DECL_SIZE_UNIT (var)))
     {
       /* Reject variables which cover more than half of the address-space.  */
       if (really_expand)
@@ -1661,9 +1677,7 @@ expand_one_var (tree var, bool toplevel, bool really_expand)
 
           expand_one_stack_var (origvar);
         }
-
-
-      return tree_to_uhwi (DECL_SIZE_UNIT (var));
+      return size;
     }
   return 0;
 }
@@ -1916,7 +1930,7 @@ fini_vars_expansion (void)
 HOST_WIDE_INT
 estimated_stack_frame_size (struct cgraph_node *node)
 {
-  HOST_WIDE_INT size = 0;
+  poly_int64 size = 0;
   size_t i;
   tree var;
   struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
@@ -1940,7 +1954,7 @@ estimated_stack_frame_size (struct cgraph_node *node)
 
   fini_vars_expansion ();
   pop_cfun ();
-  return size;
+  return estimated_poly_value (size);
 }
 
 /* Helper routine to check if a record or union contains an array field. */
@@ -2025,7 +2039,7 @@ expand_used_vars (void)
   /* Compute the phase of the stack frame for this function.  */
   {
     int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
-    int off = STARTING_FRAME_OFFSET % align;
+    int off = targetm.starting_frame_offset () % align;
     frame_phase = off ? align - off : 0;
   }
 
@@ -2210,9 +2224,12 @@ expand_used_vars (void)
           in addition to phase 1 and 2.  */
        expand_stack_vars (asan_decl_phase_3, &data);
 
-      if (!data.asan_vec.is_empty ())
+      /* ASAN description strings don't yet have a syntax for expressing
+        polynomial offsets.  */
+      HOST_WIDE_INT prev_offset;
+      if (!data.asan_vec.is_empty ()
+         && frame_offset.is_constant (&prev_offset))
        {
-         HOST_WIDE_INT prev_offset = frame_offset;
          HOST_WIDE_INT offset, sz, redzonesz;
          redzonesz = ASAN_RED_ZONE_SIZE;
          sz = data.asan_vec[0] - prev_offset;
@@ -2221,8 +2238,10 @@ expand_used_vars (void)
              && sz + ASAN_RED_ZONE_SIZE >= (int) data.asan_alignb)
            redzonesz = ((sz + ASAN_RED_ZONE_SIZE + data.asan_alignb - 1)
                         & ~(data.asan_alignb - HOST_WIDE_INT_1)) - sz;
-         offset
-           = alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE);
+         /* Allocating a constant amount of space from a constant
+            starting offset must give a constant result.  */
+         offset = (alloc_stack_frame_space (redzonesz, ASAN_RED_ZONE_SIZE)
+                   .to_constant ());
          data.asan_vec.safe_push (prev_offset);
          data.asan_vec.safe_push (offset);
          /* Leave space for alignment if STRICT_ALIGNMENT.  */
@@ -2267,9 +2286,10 @@ expand_used_vars (void)
   if (STACK_ALIGNMENT_NEEDED)
     {
       HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
-      if (!FRAME_GROWS_DOWNWARD)
-       frame_offset += align - 1;
-      frame_offset &= -align;
+      if (FRAME_GROWS_DOWNWARD)
+       frame_offset = aligned_lower_bound (frame_offset, align);
+      else
+       frame_offset = aligned_upper_bound (frame_offset, align);
     }
 
   return var_end_seq;
@@ -2507,8 +2527,7 @@ expand_gimple_cond (basic_block bb, gcond *stmt)
   dest = false_edge->dest;
   redirect_edge_succ (false_edge, new_bb);
   false_edge->flags |= EDGE_FALLTHRU;
-  new_bb->count = false_edge->count;
-  new_bb->frequency = EDGE_FREQUENCY (false_edge);
+  new_bb->count = false_edge->count ();
   loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);
   add_bb_to_loop (new_bb, loop);
   if (loop->latch == bb
@@ -2597,7 +2616,7 @@ expand_call_stmt (gcall *stmt)
   exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
 
   CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
-  builtin_p = decl && DECL_BUILT_IN (decl);
+  builtin_p = decl && fndecl_built_in_p (decl);
 
   /* If this is not a builtin function, the function type through which the
      call is made may be different from the type of the function.  */
@@ -2629,20 +2648,21 @@ expand_call_stmt (gcall *stmt)
   if (gimple_call_nothrow_p (stmt))
     TREE_NOTHROW (exp) = 1;
 
+  if (gimple_no_warning_p (stmt))
+    TREE_NO_WARNING (exp) = 1;
+
   CALL_EXPR_TAILCALL (exp) = gimple_call_tail_p (stmt);
   CALL_EXPR_MUST_TAIL_CALL (exp) = gimple_call_must_tail_p (stmt);
   CALL_EXPR_RETURN_SLOT_OPT (exp) = gimple_call_return_slot_opt_p (stmt);
   if (decl
-      && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
-      && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
-         || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
+      && fndecl_built_in_p (decl, BUILT_IN_NORMAL)
+      && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
     CALL_ALLOCA_FOR_VAR_P (exp) = gimple_call_alloca_for_var_p (stmt);
   else
     CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt);
   CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt);
   CALL_EXPR_BY_DESCRIPTOR (exp) = gimple_call_by_descriptor_p (stmt);
   SET_EXPR_LOCATION (exp, gimple_location (stmt));
-  CALL_WITH_BOUNDS_P (exp) = gimple_call_with_bounds_p (stmt);
 
   /* Ensure RTL is created for debug args.  */
   if (decl && DECL_HAS_DEBUG_ARGS_P (decl))
@@ -2659,12 +2679,28 @@ expand_call_stmt (gcall *stmt)
          }
     }
 
+  rtx_insn *before_call = get_last_insn ();
   lhs = gimple_call_lhs (stmt);
   if (lhs)
     expand_assignment (lhs, exp, false);
   else
     expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
 
+  /* If the gimple call is an indirect call and has 'nocf_check'
+     attribute find a generated CALL insn to mark it as no
+     control-flow verification is needed.  */
+  if (gimple_call_nocf_check_p (stmt)
+      && !gimple_call_fndecl (stmt))
+    {
+      rtx_insn *last = get_last_insn ();
+      while (!CALL_P (last)
+            && last != before_call)
+       last = PREV_INSN (last);
+
+      if (last != before_call)
+       add_reg_note (last, REG_CALL_NOCF_CHECK, const0_rtx);
+    }
+
   mark_transaction_restart_calls (stmt);
 }
 
@@ -3005,14 +3041,14 @@ expand_asm_stmt (gasm *stmt)
 
       generating_concat_p = 0;
 
-      if ((TREE_CODE (val) == INDIRECT_REF
-          && allows_mem)
+      if ((TREE_CODE (val) == INDIRECT_REF && allows_mem)
          || (DECL_P (val)
              && (allows_mem || REG_P (DECL_RTL (val)))
              && ! (REG_P (DECL_RTL (val))
                    && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
          || ! allows_reg
-         || is_inout)
+         || is_inout
+         || TREE_ADDRESSABLE (type))
        {
          op = expand_expr (val, NULL_RTX, VOIDmode,
                            !allows_reg ? EXPAND_MEMORY : EXPAND_WRITE);
@@ -3021,7 +3057,7 @@ expand_asm_stmt (gasm *stmt)
 
          if (! allows_reg && !MEM_P (op))
            error ("output number %d not directly addressable", i);
-         if ((! allows_mem && MEM_P (op))
+         if ((! allows_mem && MEM_P (op) && GET_MODE (op) != BLKmode)
              || GET_CODE (op) == CONCAT)
            {
              rtx old_op = op;
@@ -3203,7 +3239,7 @@ expand_asm_stmt (gasm *stmt)
             may insert further instructions into the same basic block after
             asm goto and if we don't do this, insertion of instructions on
             the fallthru edge might misbehave.  See PR58670.  */
-         if (fallthru_bb && label_to_block_fn (cfun, label) == fallthru_bb)
+         if (fallthru_bb && label_to_block (cfun, label) == fallthru_bb)
            {
              if (fallthru_label == NULL_RTX)
                fallthru_label = gen_label_rtx ();
@@ -3405,12 +3441,11 @@ expand_value_return (rtx val)
    from the current function.  */
 
 static void
-expand_return (tree retval, tree bounds)
+expand_return (tree retval)
 {
   rtx result_rtl;
   rtx val = 0;
   tree retval_rhs;
-  rtx bounds_rtl;
 
   /* If function wants no value, give it none.  */
   if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) == VOID_TYPE)
@@ -3436,71 +3471,6 @@ expand_return (tree retval, tree bounds)
 
   result_rtl = DECL_RTL (DECL_RESULT (current_function_decl));
 
-  /* Put returned bounds to the right place.  */
-  bounds_rtl = DECL_BOUNDS_RTL (DECL_RESULT (current_function_decl));
-  if (bounds_rtl)
-    {
-      rtx addr = NULL;
-      rtx bnd = NULL;
-
-      if (bounds && bounds != error_mark_node)
-       {
-         bnd = expand_normal (bounds);
-         targetm.calls.store_returned_bounds (bounds_rtl, bnd);
-       }
-      else if (REG_P (bounds_rtl))
-       {
-         if (bounds)
-           bnd = chkp_expand_zero_bounds ();
-         else
-           {
-             addr = expand_normal (build_fold_addr_expr (retval_rhs));
-             addr = gen_rtx_MEM (Pmode, addr);
-             bnd = targetm.calls.load_bounds_for_arg (addr, NULL, NULL);
-           }
-
-         targetm.calls.store_returned_bounds (bounds_rtl, bnd);
-       }
-      else
-       {
-         int n;
-
-         gcc_assert (GET_CODE (bounds_rtl) == PARALLEL);
-
-         if (bounds)
-           bnd = chkp_expand_zero_bounds ();
-         else
-           {
-             addr = expand_normal (build_fold_addr_expr (retval_rhs));
-             addr = gen_rtx_MEM (Pmode, addr);
-           }
-
-         for (n = 0; n < XVECLEN (bounds_rtl, 0); n++)
-           {
-             rtx slot = XEXP (XVECEXP (bounds_rtl, 0, n), 0);
-             if (!bounds)
-               {
-                 rtx offs = XEXP (XVECEXP (bounds_rtl, 0, n), 1);
-                 rtx from = adjust_address (addr, Pmode, INTVAL (offs));
-                 bnd = targetm.calls.load_bounds_for_arg (from, NULL, NULL);
-               }
-             targetm.calls.store_returned_bounds (slot, bnd);
-           }
-       }
-    }
-  else if (chkp_function_instrumented_p (current_function_decl)
-          && !BOUNDED_P (retval_rhs)
-          && chkp_type_has_pointer (TREE_TYPE (retval_rhs))
-          && TREE_CODE (retval_rhs) != RESULT_DECL)
-    {
-      rtx addr = expand_normal (build_fold_addr_expr (retval_rhs));
-      addr = gen_rtx_MEM (Pmode, addr);
-
-      gcc_assert (MEM_P (result_rtl));
-
-      chkp_copy_bounds_for_stack_parm (result_rtl, addr, TREE_TYPE (retval_rhs));
-    }
-
   /* If we are returning the RESULT_DECL, then the value has already
      been stored into it, so we don't have to do anything special.  */
   if (TREE_CODE (retval_rhs) == RESULT_DECL)
@@ -3543,6 +3513,26 @@ expand_return (tree retval, tree bounds)
     }
 }
 
+/* Expand a clobber of LHS.  If LHS is stored it in a multi-part
+   register, tell the rtl optimizers that its value is no longer
+   needed.  */
+
+static void
+expand_clobber (tree lhs)
+{
+  if (DECL_P (lhs))
+    {
+      rtx decl_rtl = DECL_RTL_IF_SET (lhs);
+      if (decl_rtl && REG_P (decl_rtl))
+       {
+         machine_mode decl_mode = GET_MODE (decl_rtl);
+         if (maybe_gt (GET_MODE_SIZE (decl_mode),
+                       REGMODE_NATURAL_SIZE (decl_mode)))
+           emit_clobber (decl_rtl);
+       }
+    }
+}
+
 /* A subroutine of expand_gimple_stmt, expanding one gimple statement
    STMT that doesn't require special handling for outgoing edges.  That
    is no tailcalls and no GIMPLE_COND.  */
@@ -3587,19 +3577,12 @@ expand_gimple_stmt_1 (gimple *stmt)
 
     case GIMPLE_RETURN:
       {
-       tree bnd = gimple_return_retbnd (as_a <greturn *> (stmt));
        op0 = gimple_return_retval (as_a <greturn *> (stmt));
 
        if (op0 && op0 != error_mark_node)
          {
            tree result = DECL_RESULT (current_function_decl);
 
-           /* Mark we have return statement with missing bounds.  */
-           if (!bnd
-               && chkp_function_instrumented_p (cfun->decl)
-               && !DECL_P (op0))
-             bnd = error_mark_node;
-
            /* If we are not returning the current function's RESULT_DECL,
               build an assignment to it.  */
            if (op0 != result)
@@ -3621,7 +3604,7 @@ expand_gimple_stmt_1 (gimple *stmt)
        if (!op0)
          expand_null_return ();
        else
-         expand_return (op0, bnd);
+         expand_return (op0);
       }
       break;
 
@@ -3648,7 +3631,7 @@ expand_gimple_stmt_1 (gimple *stmt)
            if (TREE_CLOBBER_P (rhs))
              /* This is a clobber to mark the going out of scope for
                 this LHS.  */
-             ;
+             expand_clobber (lhs);
            else
              expand_assignment (lhs, rhs,
                                 gimple_assign_nontemporal_move_p (
@@ -3767,6 +3750,7 @@ expand_gimple_stmt (gimple *stmt)
              /* If we want exceptions for non-call insns, any
                 may_trap_p instruction may throw.  */
              && GET_CODE (PATTERN (insn)) != CLOBBER
+             && GET_CODE (PATTERN (insn)) != CLOBBER_HIGH
              && GET_CODE (PATTERN (insn)) != USE
              && insn_could_throw_p (insn))
            make_reg_eh_region_note (insn, 0, lp_nr);
@@ -3818,20 +3802,13 @@ expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru)
      the exit block.  */
 
   probability = profile_probability::never ();
-  profile_count count = profile_count::zero ();
 
   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
     {
       if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
        {
          if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
-           {
-             e->dest->count -= e->count;
-             e->dest->frequency -= EDGE_FREQUENCY (e);
-             if (e->dest->frequency < 0)
-               e->dest->frequency = 0;
-           }
-         count += e->count;
+           e->dest->count -= e->count ();
          probability += e->probability;
          remove_edge (e);
        }
@@ -3861,7 +3838,6 @@ expand_gimple_tailcall (basic_block bb, gcall *stmt, bool *can_fallthru)
   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_ABNORMAL
                 | EDGE_SIBCALL);
   e->probability = probability;
-  e->count = count;
   BB_END (bb) = last;
   update_bb_for_insn (bb);
 
@@ -3962,15 +3938,13 @@ round_udiv_adjust (machine_mode mode, rtx mod, rtx op1)
    any rtl.  */
 
 static rtx
-convert_debug_memory_address (machine_mode mode, rtx x,
+convert_debug_memory_address (scalar_int_mode mode, rtx x,
                              addr_space_t as)
 {
-  machine_mode xmode = GET_MODE (x);
-
 #ifndef POINTERS_EXTEND_UNSIGNED
   gcc_assert (mode == Pmode
              || mode == targetm.addr_space.address_mode (as));
-  gcc_assert (xmode == mode || xmode == VOIDmode);
+  gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
 #else
   rtx temp;
 
@@ -3979,6 +3953,8 @@ convert_debug_memory_address (machine_mode mode, rtx x,
   if (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode)
     return x;
 
+  /* X must have some form of address mode already.  */
+  scalar_int_mode xmode = as_a <scalar_int_mode> (GET_MODE (x));
   if (GET_MODE_PRECISION (mode) < GET_MODE_PRECISION (xmode))
     x = lowpart_subreg (mode, x, xmode);
   else if (POINTERS_EXTEND_UNSIGNED > 0)
@@ -4139,6 +4115,7 @@ expand_debug_expr (tree exp)
   machine_mode inner_mode = VOIDmode;
   int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
   addr_space_t as;
+  scalar_int_mode op0_mode, op1_mode, addr_mode;
 
   switch (TREE_CODE_CLASS (TREE_CODE (exp)))
     {
@@ -4150,7 +4127,6 @@ expand_debug_expr (tree exp)
        case SAD_EXPR:
        case WIDEN_MULT_PLUS_EXPR:
        case WIDEN_MULT_MINUS_EXPR:
-       case FMA_EXPR:
          goto ternary;
 
        case TRUTH_ANDIF_EXPR:
@@ -4176,6 +4152,8 @@ expand_debug_expr (tree exp)
 
     binary:
     case tcc_binary:
+      if (mode == BLKmode)
+       return NULL_RTX;
       op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
       if (!op1)
        return NULL_RTX;
@@ -4188,16 +4166,10 @@ expand_debug_expr (tree exp)
        case WIDEN_LSHIFT_EXPR:
          /* Ensure second operand isn't wider than the first one.  */
          inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
-         if (SCALAR_INT_MODE_P (inner_mode))
-           {
-             machine_mode opmode = mode;
-             if (VECTOR_MODE_P (mode))
-               opmode = GET_MODE_INNER (mode);
-             if (SCALAR_INT_MODE_P (opmode)
-                 && (GET_MODE_PRECISION (opmode)
-                     < GET_MODE_PRECISION (inner_mode)))
-               op1 = lowpart_subreg (opmode, op1, inner_mode);
-           }
+         if (is_a <scalar_int_mode> (inner_mode, &op1_mode)
+             && (GET_MODE_UNIT_PRECISION (mode)
+                 < GET_MODE_PRECISION (op1_mode)))
+           op1 = lowpart_subreg (GET_MODE_INNER (mode), op1, op1_mode);
          break;
        default:
          break;
@@ -4206,6 +4178,8 @@ expand_debug_expr (tree exp)
 
     unary:
     case tcc_unary:
+      if (mode == BLKmode)
+       return NULL_RTX;
       inner_mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
       if (!op0)
@@ -4249,6 +4223,9 @@ expand_debug_expr (tree exp)
       op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER);
       return op0;
 
+    case POLY_INT_CST:
+      return immed_wide_int_const (poly_int_cst_value (exp), mode);
+
     case COMPLEX_CST:
       gcc_assert (COMPLEX_MODE_P (mode));
       op0 = expand_debug_expr (TREE_REALPART (exp));
@@ -4331,9 +4308,11 @@ expand_debug_expr (tree exp)
 
        if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
          {
-           if (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (inner_mode))
+           if (GET_MODE_UNIT_BITSIZE (mode)
+               == GET_MODE_UNIT_BITSIZE (inner_mode))
              op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
-           else if (GET_MODE_BITSIZE (mode) < GET_MODE_BITSIZE (inner_mode))
+           else if (GET_MODE_UNIT_BITSIZE (mode)
+                    < GET_MODE_UNIT_BITSIZE (inner_mode))
              op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
            else
              op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
@@ -4353,9 +4332,12 @@ expand_debug_expr (tree exp)
            else
              op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
          }
-       else if (CONSTANT_P (op0)
-                || GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (inner_mode))
+       else if (GET_MODE_UNIT_PRECISION (mode)
+                == GET_MODE_UNIT_PRECISION (inner_mode))
          op0 = lowpart_subreg (mode, op0, inner_mode);
+       else if (GET_MODE_UNIT_PRECISION (mode)
+                < GET_MODE_UNIT_PRECISION (inner_mode))
+         op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
        else if (UNARY_CLASS_P (exp)
                 ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)))
                 : unsignedp)
@@ -4392,10 +4374,11 @@ expand_debug_expr (tree exp)
            goto component_ref;
 
          op1 = expand_debug_expr (TREE_OPERAND (exp, 1));
-         if (!op1 || !CONST_INT_P (op1))
+         poly_int64 offset;
+         if (!op1 || !poly_int_rtx_p (op1, &offset))
            return NULL;
 
-         op0 = plus_constant (inner_mode, op0, INTVAL (op1));
+         op0 = plus_constant (inner_mode, op0, offset);
        }
 
       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
@@ -4447,7 +4430,7 @@ expand_debug_expr (tree exp)
     case VIEW_CONVERT_EXPR:
       {
        machine_mode mode1;
-       HOST_WIDE_INT bitsize, bitpos;
+       poly_int64 bitsize, bitpos;
        tree offset;
        int reversep, volatilep = 0;
        tree tem
@@ -4455,7 +4438,7 @@ expand_debug_expr (tree exp)
                                 &unsignedp, &reversep, &volatilep);
        rtx orig_op0;
 
-       if (bitsize == 0)
+       if (known_eq (bitsize, 0))
          return NULL;
 
        orig_op0 = op0 = expand_debug_expr (tem);
@@ -4496,21 +4479,20 @@ expand_debug_expr (tree exp)
        if (MEM_P (op0))
          {
            if (mode1 == VOIDmode)
-             /* Bitfield.  */
-             mode1 = smallest_mode_for_size (bitsize, MODE_INT);
-           if (bitpos >= BITS_PER_UNIT)
              {
-               op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
-               bitpos %= BITS_PER_UNIT;
+               if (maybe_gt (bitsize, MAX_BITSIZE_MODE_ANY_INT))
+                 return NULL;
+               /* Bitfield.  */
+               mode1 = smallest_int_mode_for_size (bitsize);
              }
-           else if (bitpos < 0)
+           poly_int64 bytepos = bits_to_bytes_round_down (bitpos);
+           if (maybe_ne (bytepos, 0))
              {
-               HOST_WIDE_INT units
-                 = (-bitpos + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
-               op0 = adjust_address_nv (op0, mode1, -units);
-               bitpos += units * BITS_PER_UNIT;
+               op0 = adjust_address_nv (op0, mode1, bytepos);
+               bitpos = num_trailing_bits (bitpos);
              }
-           else if (bitpos == 0 && bitsize == GET_MODE_BITSIZE (mode))
+           else if (known_eq (bitpos, 0)
+                    && known_eq (bitsize, GET_MODE_BITSIZE (mode)))
              op0 = adjust_address_nv (op0, mode, 0);
            else if (GET_MODE (op0) != mode1)
              op0 = adjust_address_nv (op0, mode1, 0);
@@ -4521,17 +4503,18 @@ expand_debug_expr (tree exp)
            set_mem_attributes (op0, exp, 0);
          }
 
-       if (bitpos == 0 && mode == GET_MODE (op0))
+       if (known_eq (bitpos, 0) && mode == GET_MODE (op0))
          return op0;
 
-        if (bitpos < 0)
+       if (maybe_lt (bitpos, 0))
           return NULL;
 
-       if (GET_MODE (op0) == BLKmode)
+       if (GET_MODE (op0) == BLKmode || mode == BLKmode)
          return NULL;
 
-       if ((bitpos % BITS_PER_UNIT) == 0
-           && bitsize == GET_MODE_BITSIZE (mode1))
+       poly_int64 bytepos;
+       if (multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
+           && known_eq (bitsize, GET_MODE_BITSIZE (mode1)))
          {
            machine_mode opmode = GET_MODE (op0);
 
@@ -4544,12 +4527,11 @@ expand_debug_expr (tree exp)
               debug stmts).  The gen_subreg below would rightfully
               crash, and the address doesn't really exist, so just
               drop it.  */
-           if (bitpos >= GET_MODE_BITSIZE (opmode))
+           if (known_ge (bitpos, GET_MODE_BITSIZE (opmode)))
              return NULL;
 
-           if ((bitpos % GET_MODE_BITSIZE (mode)) == 0)
-             return simplify_gen_subreg (mode, op0, opmode,
-                                         bitpos / BITS_PER_UNIT);
+           if (multiple_p (bitpos, GET_MODE_BITSIZE (mode)))
+             return simplify_gen_subreg (mode, op0, opmode, bytepos);
          }
 
        return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0))
@@ -4559,10 +4541,12 @@ expand_debug_expr (tree exp)
                                     GET_MODE (op0) != VOIDmode
                                     ? GET_MODE (op0)
                                     : TYPE_MODE (TREE_TYPE (tem)),
-                                    op0, GEN_INT (bitsize), GEN_INT (bitpos));
+                                    op0, gen_int_mode (bitsize, word_mode),
+                                    gen_int_mode (bitpos, word_mode));
       }
 
     case ABS_EXPR:
+    case ABSU_EXPR:
       return simplify_gen_unary (ABS, mode, op0, mode);
 
     case NEGATE_EXPR:
@@ -4586,29 +4570,30 @@ expand_debug_expr (tree exp)
         size_t, we need to check for mis-matched modes and correct
         the addend.  */
       if (op0 && op1
-         && GET_MODE (op0) != VOIDmode && GET_MODE (op1) != VOIDmode
-         && GET_MODE (op0) != GET_MODE (op1))
+         && is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode)
+         && is_a <scalar_int_mode> (GET_MODE (op1), &op1_mode)
+         && op0_mode != op1_mode)
        {
-         if (GET_MODE_BITSIZE (GET_MODE (op0)) < GET_MODE_BITSIZE (GET_MODE (op1))
-             /* If OP0 is a partial mode, then we must truncate, even if it has
-                the same bitsize as OP1 as GCC's representation of partial modes
-                is opaque.  */
-             || (GET_MODE_CLASS (GET_MODE (op0)) == MODE_PARTIAL_INT
-                 && GET_MODE_BITSIZE (GET_MODE (op0)) == GET_MODE_BITSIZE (GET_MODE (op1))))
-           op1 = simplify_gen_unary (TRUNCATE, GET_MODE (op0), op1,
-                                     GET_MODE (op1));
+         if (GET_MODE_BITSIZE (op0_mode) < GET_MODE_BITSIZE (op1_mode)
+             /* If OP0 is a partial mode, then we must truncate, even
+                if it has the same bitsize as OP1 as GCC's
+                representation of partial modes is opaque.  */
+             || (GET_MODE_CLASS (op0_mode) == MODE_PARTIAL_INT
+                 && (GET_MODE_BITSIZE (op0_mode)
+                     == GET_MODE_BITSIZE (op1_mode))))
+           op1 = simplify_gen_unary (TRUNCATE, op0_mode, op1, op1_mode);
          else
            /* We always sign-extend, regardless of the signedness of
               the operand, because the operand is always unsigned
               here even if the original C expression is signed.  */
-           op1 = simplify_gen_unary (SIGN_EXTEND, GET_MODE (op0), op1,
-                                     GET_MODE (op1));
+           op1 = simplify_gen_unary (SIGN_EXTEND, op0_mode, op1, op1_mode);
        }
       /* Fall through.  */
     case PLUS_EXPR:
       return simplify_gen_binary (PLUS, mode, op0, op1);
 
     case MINUS_EXPR:
+    case POINTER_DIFF_EXPR:
       return simplify_gen_binary (MINUS, mode, op0, op1);
 
     case MULT_EXPR:
@@ -4828,7 +4813,7 @@ expand_debug_expr (tree exp)
                                                   GET_MODE_INNER (mode)));
       else
        {
-         machine_mode imode = GET_MODE_INNER (mode);
+         scalar_mode imode = GET_MODE_INNER (mode);
          rtx re, im;
 
          if (MEM_P (op0))
@@ -4875,7 +4860,7 @@ expand_debug_expr (tree exp)
 
          if (handled_component_p (TREE_OPERAND (exp, 0)))
            {
-             HOST_WIDE_INT bitoffset, bitsize, maxsize;
+             poly_int64 bitoffset, bitsize, maxsize, byteoffset;
              bool reverse;
              tree decl
                = get_ref_base_and_extent (TREE_OPERAND (exp, 0), &bitoffset,
@@ -4885,12 +4870,12 @@ expand_debug_expr (tree exp)
                   || TREE_CODE (decl) == RESULT_DECL)
                  && (!TREE_ADDRESSABLE (decl)
                      || target_for_debug_bind (decl))
-                 && (bitoffset % BITS_PER_UNIT) == 0
-                 && bitsize > 0
-                 && bitsize == maxsize)
+                 && multiple_p (bitoffset, BITS_PER_UNIT, &byteoffset)
+                 && known_gt (bitsize, 0)
+                 && known_eq (bitsize, maxsize))
                {
                  rtx base = gen_rtx_DEBUG_IMPLICIT_PTR (mode, decl);
-                 return plus_constant (mode, base, bitoffset / BITS_PER_UNIT);
+                 return plus_constant (mode, base, byteoffset);
                }
            }
 
@@ -4908,10 +4893,11 @@ expand_debug_expr (tree exp)
                {
                  op1 = expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp, 0),
                                                         1));
-                 if (!op1 || !CONST_INT_P (op1))
+                 poly_int64 offset;
+                 if (!op1 || !poly_int_rtx_p (op1, &offset))
                    return NULL;
 
-                 return plus_constant (mode, op0, INTVAL (op1));
+                 return plus_constant (mode, op0, offset);
                }
            }
 
@@ -4919,18 +4905,21 @@ expand_debug_expr (tree exp)
        }
 
       as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
-      op0 = convert_debug_memory_address (mode, XEXP (op0, 0), as);
+      addr_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (exp));
+      op0 = convert_debug_memory_address (addr_mode, XEXP (op0, 0), as);
 
       return op0;
 
     case VECTOR_CST:
       {
-       unsigned i;
+       unsigned HOST_WIDE_INT i, nelts;
+
+       if (!VECTOR_CST_NELTS (exp).is_constant (&nelts))
+         return NULL;
 
-       op0 = gen_rtx_CONCATN
-         (mode, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp))));
+       op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
 
-       for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
+       for (i = 0; i < nelts; ++i)
          {
            op1 = expand_debug_expr (VECTOR_CST_ELT (exp, i));
            if (!op1)
@@ -4947,10 +4936,13 @@ expand_debug_expr (tree exp)
       else if (TREE_CODE (TREE_TYPE (exp)) == VECTOR_TYPE)
        {
          unsigned i;
+         unsigned HOST_WIDE_INT nelts;
          tree val;
 
-         op0 = gen_rtx_CONCATN
-           (mode, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp))));
+         if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)).is_constant (&nelts))
+           goto flag_unsupported;
+
+         op0 = gen_rtx_CONCATN (mode, rtvec_alloc (nelts));
 
          FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), i, val)
            {
@@ -4960,7 +4952,7 @@ expand_debug_expr (tree exp)
              XVECEXP (op0, 0, i) = op1;
            }
 
-         if (i < TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)))
+         if (i < nelts)
            {
              op1 = expand_debug_expr
                (build_zero_cst (TREE_TYPE (TREE_TYPE (exp))));
@@ -4968,7 +4960,7 @@ expand_debug_expr (tree exp)
              if (!op1)
                return NULL;
 
-             for (; i < TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp)); i++)
+             for (; i < nelts; i++)
                XVECEXP (op0, 0, i) = op1;
            }
 
@@ -5035,13 +5027,13 @@ expand_debug_expr (tree exp)
 
     /* Vector stuff.  For most of the codes we don't have rtl codes.  */
     case REALIGN_LOAD_EXPR:
-    case REDUC_MAX_EXPR:
-    case REDUC_MIN_EXPR:
-    case REDUC_PLUS_EXPR:
     case VEC_COND_EXPR:
     case VEC_PACK_FIX_TRUNC_EXPR:
+    case VEC_PACK_FLOAT_EXPR:
     case VEC_PACK_SAT_EXPR:
     case VEC_PACK_TRUNC_EXPR:
+    case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
+    case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
     case VEC_UNPACK_FLOAT_HI_EXPR:
     case VEC_UNPACK_FLOAT_LO_EXPR:
     case VEC_UNPACK_HI_EXPR:
@@ -5053,6 +5045,8 @@ expand_debug_expr (tree exp)
     case VEC_WIDEN_LSHIFT_HI_EXPR:
     case VEC_WIDEN_LSHIFT_LO_EXPR:
     case VEC_PERM_EXPR:
+    case VEC_DUPLICATE_EXPR:
+    case VEC_SERIES_EXPR:
       return NULL;
 
     /* Misc codes.  */
@@ -5126,9 +5120,6 @@ expand_debug_expr (tree exp)
        }
       return NULL;
 
-    case FMA_EXPR:
-      return simplify_gen_ternary (FMA, mode, inner_mode, op0, op1, op2);
-
     default:
     flag_unsupported:
       if (flag_checking)
@@ -5151,6 +5142,10 @@ expand_debug_source_expr (tree exp)
 
   switch (TREE_CODE (exp))
     {
+    case VAR_DECL:
+      if (DECL_ABSTRACT_ORIGIN (exp))
+       return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp));
+      break;
     case PARM_DECL:
       {
        mode = DECL_MODE (exp);
@@ -5195,9 +5190,11 @@ expand_debug_source_expr (tree exp)
 
   if (FLOAT_MODE_P (mode) && FLOAT_MODE_P (inner_mode))
     {
-      if (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (inner_mode))
+      if (GET_MODE_UNIT_BITSIZE (mode)
+         == GET_MODE_UNIT_BITSIZE (inner_mode))
        op0 = simplify_gen_subreg (mode, op0, inner_mode, 0);
-      else if (GET_MODE_BITSIZE (mode) < GET_MODE_BITSIZE (inner_mode))
+      else if (GET_MODE_UNIT_BITSIZE (mode)
+              < GET_MODE_UNIT_BITSIZE (inner_mode))
        op0 = simplify_gen_unary (FLOAT_TRUNCATE, mode, op0, inner_mode);
       else
        op0 = simplify_gen_unary (FLOAT_EXTEND, mode, op0, inner_mode);
@@ -5211,9 +5208,12 @@ expand_debug_source_expr (tree exp)
       else
        op0 = simplify_gen_unary (FIX, mode, op0, inner_mode);
     }
-  else if (CONSTANT_P (op0)
-          || GET_MODE_BITSIZE (mode) <= GET_MODE_BITSIZE (inner_mode))
+  else if (GET_MODE_UNIT_PRECISION (mode)
+          == GET_MODE_UNIT_PRECISION (inner_mode))
     op0 = lowpart_subreg (mode, op0, inner_mode);
+  else if (GET_MODE_UNIT_PRECISION (mode)
+          < GET_MODE_UNIT_PRECISION (inner_mode))
+    op0 = simplify_gen_unary (TRUNCATE, mode, op0, inner_mode);
   else if (TYPE_UNSIGNED (TREE_TYPE (exp)))
     op0 = simplify_gen_unary (ZERO_EXTEND, mode, op0, inner_mode);
   else
@@ -5289,7 +5289,7 @@ expand_debug_locations (void)
   flag_strict_aliasing = 0;
 
   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-    if (DEBUG_INSN_P (insn))
+    if (DEBUG_BIND_INSN_P (insn))
       {
        tree value = (tree)INSN_VAR_LOCATION_LOC (insn);
        rtx val;
@@ -5436,7 +5436,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
   gimple_stmt_iterator gsi;
   gimple_seq stmts;
   gimple *stmt = NULL;
-  rtx_note *note;
+  rtx_note *note = NULL;
   rtx_insn *last;
   edge e;
   edge_iterator ei;
@@ -5489,6 +5489,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
 
   if (stmt || elt)
     {
+      gcc_checking_assert (!note);
       last = get_last_insn ();
 
       if (stmt)
@@ -5503,6 +5504,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
       BB_HEAD (bb) = NEXT_INSN (last);
       if (NOTE_P (BB_HEAD (bb)))
        BB_HEAD (bb) = NEXT_INSN (BB_HEAD (bb));
+      gcc_assert (LABEL_P (BB_HEAD (bb)));
       note = emit_note_after (NOTE_INSN_BASIC_BLOCK, BB_HEAD (bb));
 
       maybe_dump_rtl_for_gimple_stmt (stmt, last);
@@ -5510,7 +5512,8 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
   else
     BB_HEAD (bb) = note = emit_note (NOTE_INSN_BASIC_BLOCK);
 
-  NOTE_BASIC_BLOCK (note) = bb;
+  if (note)
+    NOTE_BASIC_BLOCK (note) = bb;
 
   for (; !gsi_end_p (gsi); gsi_next (&gsi))
     {
@@ -5542,7 +5545,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
           a_2 = ...
            #DEBUG ... => #D1
         */
-      if (MAY_HAVE_DEBUG_INSNS
+      if (MAY_HAVE_DEBUG_BIND_INSNS
          && SA.values
          && !is_gimple_debug (stmt))
        {
@@ -5623,49 +5626,92 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
          if (new_bb)
            return new_bb;
        }
-      else if (gimple_debug_bind_p (stmt))
+      else if (is_gimple_debug (stmt))
        {
          location_t sloc = curr_insn_location ();
          gimple_stmt_iterator nsi = gsi;
 
          for (;;)
            {
-             tree var = gimple_debug_bind_get_var (stmt);
-             tree value;
-             rtx val;
+             tree var;
+             tree value = NULL_TREE;
+             rtx val = NULL_RTX;
              machine_mode mode;
 
-             if (TREE_CODE (var) != DEBUG_EXPR_DECL
-                 && TREE_CODE (var) != LABEL_DECL
-                 && !target_for_debug_bind (var))
+             if (!gimple_debug_nonbind_marker_p (stmt))
+               {
+                 if (gimple_debug_bind_p (stmt))
+                   {
+                     var = gimple_debug_bind_get_var (stmt);
+
+                     if (TREE_CODE (var) != DEBUG_EXPR_DECL
+                         && TREE_CODE (var) != LABEL_DECL
+                         && !target_for_debug_bind (var))
+                       goto delink_debug_stmt;
+
+                     if (DECL_P (var))
+                       mode = DECL_MODE (var);
+                     else
+                       mode = TYPE_MODE (TREE_TYPE (var));
+
+                     if (gimple_debug_bind_has_value_p (stmt))
+                       value = gimple_debug_bind_get_value (stmt);
+
+                     val = gen_rtx_VAR_LOCATION
+                       (mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
+                   }
+                 else if (gimple_debug_source_bind_p (stmt))
+                   {
+                     var = gimple_debug_source_bind_get_var (stmt);
+
+                     value = gimple_debug_source_bind_get_value (stmt);
+
+                     mode = DECL_MODE (var);
+
+                     val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value,
+                                                 VAR_INIT_STATUS_UNINITIALIZED);
+                   }
+                 else
+                   gcc_unreachable ();
+               }
+             /* If this function was first compiled with markers
+                enabled, but they're now disable (e.g. LTO), drop
+                them on the floor.  */
+             else if (gimple_debug_nonbind_marker_p (stmt)
+                      && !MAY_HAVE_DEBUG_MARKER_INSNS)
                goto delink_debug_stmt;
+             else if (gimple_debug_begin_stmt_p (stmt))
+               val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT ();
+             else if (gimple_debug_inline_entry_p (stmt))
+               {
+                 tree block = gimple_block (stmt);
 
-             if (gimple_debug_bind_has_value_p (stmt))
-               value = gimple_debug_bind_get_value (stmt);
+                 if (block)
+                   val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
+                 else
+                   goto delink_debug_stmt;
+               }
              else
-               value = NULL_TREE;
+               gcc_unreachable ();
 
              last = get_last_insn ();
 
              set_curr_insn_location (gimple_location (stmt));
 
-             if (DECL_P (var))
-               mode = DECL_MODE (var);
-             else
-               mode = TYPE_MODE (TREE_TYPE (var));
-
-             val = gen_rtx_VAR_LOCATION
-               (mode, var, (rtx)value, VAR_INIT_STATUS_INITIALIZED);
-
              emit_debug_insn (val);
 
              if (dump_file && (dump_flags & TDF_DETAILS))
                {
                  /* We can't dump the insn with a TREE where an RTX
                     is expected.  */
-                 PAT_VAR_LOCATION_LOC (val) = const0_rtx;
+                 if (GET_CODE (val) == VAR_LOCATION)
+                   {
+                     gcc_checking_assert (PAT_VAR_LOCATION_LOC (val) == (rtx)value);
+                     PAT_VAR_LOCATION_LOC (val) = const0_rtx;
+                   }
                  maybe_dump_rtl_for_gimple_stmt (stmt, last);
-                 PAT_VAR_LOCATION_LOC (val) = (rtx)value;
+                 if (GET_CODE (val) == VAR_LOCATION)
+                   PAT_VAR_LOCATION_LOC (val) = (rtx)value;
                }
 
            delink_debug_stmt:
@@ -5681,40 +5727,10 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
              if (gsi_end_p (nsi))
                break;
              stmt = gsi_stmt (nsi);
-             if (!gimple_debug_bind_p (stmt))
+             if (!is_gimple_debug (stmt))
                break;
            }
 
-         set_curr_insn_location (sloc);
-       }
-      else if (gimple_debug_source_bind_p (stmt))
-       {
-         location_t sloc = curr_insn_location ();
-         tree var = gimple_debug_source_bind_get_var (stmt);
-         tree value = gimple_debug_source_bind_get_value (stmt);
-         rtx val;
-         machine_mode mode;
-
-         last = get_last_insn ();
-
-         set_curr_insn_location (gimple_location (stmt));
-
-         mode = DECL_MODE (var);
-
-         val = gen_rtx_VAR_LOCATION (mode, var, (rtx)value,
-                                     VAR_INIT_STATUS_UNINITIALIZED);
-
-         emit_debug_insn (val);
-
-         if (dump_file && (dump_flags & TDF_DETAILS))
-           {
-             /* We can't dump the insn with a TREE where an RTX
-                is expected.  */
-             PAT_VAR_LOCATION_LOC (val) = const0_rtx;
-             maybe_dump_rtl_for_gimple_stmt (stmt, last);
-             PAT_VAR_LOCATION_LOC (val) = (rtx)value;
-           }
-
          set_curr_insn_location (sloc);
        }
       else
@@ -5835,7 +5851,6 @@ construct_init_block (void)
   init_block = create_basic_block (NEXT_INSN (get_insns ()),
                                   get_last_insn (),
                                   ENTRY_BLOCK_PTR_FOR_FN (cfun));
-  init_block->frequency = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;
   init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
   add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
   if (e)
@@ -5899,7 +5914,7 @@ construct_exit_block (void)
   while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
     head = NEXT_INSN (head);
   /* But make sure exit_block starts with RETURN_LABEL, otherwise the
-     bb frequency counting will be confused.  Any instructions before that
+     bb count counting will be confused.  Any instructions before that
      label are emitted for the case where PREV_BB falls through into the
      exit block, so append those instructions to prev_bb in that case.  */
   if (NEXT_INSN (head) != return_label)
@@ -5912,7 +5927,6 @@ construct_exit_block (void)
        }
     }
   exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);
-  exit_block->frequency = EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency;
   exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;
   add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);
 
@@ -5931,12 +5945,8 @@ construct_exit_block (void)
   FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
     if (e2 != e)
       {
-       e->count -= e2->count;
-       exit_block->count -= e2->count;
-       exit_block->frequency -= EDGE_FREQUENCY (e2);
+       exit_block->count -= e2->count ();
       }
-  if (exit_block->frequency < 0)
-    exit_block->frequency = 0;
   update_bb_for_insn (exit_block);
 }
 
@@ -6065,7 +6075,7 @@ expand_stack_alignment (void)
   gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
 
   /* Do nothing if NULL is returned, which means DRAP is not needed.  */
-  if (NULL != drap_rtx)
+  if (drap_rtx != NULL)
     {
       crtl->args.internal_arg_pointer = drap_rtx;
 
@@ -6083,7 +6093,7 @@ expand_main_function (void)
      || (!defined(HAS_INIT_SECTION)                    \
         && !defined(INIT_SECTION_ASM_OP)               \
         && !defined(INIT_ARRAY_SECTION_ASM_OP)))
-  emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode, 0);
+  emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode);
 #endif
 }
 \f
@@ -6169,7 +6179,7 @@ pass_expand::execute (function *fun)
   timevar_pop (TV_OUT_OF_SSA);
   SA.partition_to_pseudo = XCNEWVEC (rtx, SA.map->num_partitions);
 
-  if (MAY_HAVE_DEBUG_STMTS && flag_tree_ter)
+  if (MAY_HAVE_DEBUG_BIND_STMTS && flag_tree_ter)
     {
       gimple_stmt_iterator gsi;
       FOR_EACH_BB_FN (bb, cfun)
@@ -6189,9 +6199,6 @@ pass_expand::execute (function *fun)
 
   rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
 
-  if (chkp_function_instrumented_p (current_function_decl))
-    chkp_reset_rtl_bounds ();
-
   insn_locations_init ();
   if (!DECL_IS_BUILTIN (current_function_decl))
     {
@@ -6355,12 +6362,17 @@ pass_expand::execute (function *fun)
   FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs)
     e->flags &= ~EDGE_EXECUTABLE;
 
+  /* If the function has too many markers, drop them while expanding.  */
+  if (cfun->debug_marker_count
+      >= PARAM_VALUE (PARAM_MAX_DEBUG_MARKER_COUNT))
+    cfun->debug_nonbind_markers = false;
+
   lab_rtx_for_bb = new hash_map<basic_block, rtx_code_label *>;
   FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR_FOR_FN (fun),
                  next_bb)
     bb = expand_gimple_basic_block (bb, var_ret_seq != NULL_RTX);
 
-  if (MAY_HAVE_DEBUG_INSNS)
+  if (MAY_HAVE_DEBUG_BIND_INSNS)
     expand_debug_locations ();
 
   if (deep_ter_debug_map)