]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/tree-ssa-loop-ivopts.c
Implement -Wimplicit-fallthrough.
[thirdparty/gcc.git] / gcc / tree-ssa-loop-ivopts.c
index 1e8d6377360c07ecb2fec78bf232d7ddeb54e454..7f78734ea229fda7c46751e9ba7ac281d8730bc7 100644 (file)
@@ -115,8 +115,6 @@ along with GCC; see the file COPYING3.  If not see
 /* The infinite cost.  */
 #define INFTY 10000000
 
-#define AVG_LOOP_NITER(LOOP) 5
-
 /* Returns the expected number of loop iterations for LOOP.
    The average trip count is computed from profile data if it
    exists. */
@@ -128,8 +126,9 @@ avg_loop_niter (struct loop *loop)
   if (niter == -1)
     {
       niter = likely_max_stmt_executions_int (loop);
-      if (niter == -1 || niter > AVG_LOOP_NITER (loop))
-       return AVG_LOOP_NITER (loop);
+
+      if (niter == -1 || niter > PARAM_VALUE (PARAM_AVG_LOOP_NITER))
+       return PARAM_VALUE (PARAM_AVG_LOOP_NITER);
     }
 
   return niter;
@@ -1181,6 +1180,10 @@ alloc_iv (struct ivopts_data *data, tree base, tree step,
   iv->biv_p = false;
   iv->nonlin_use = NULL;
   iv->ssa_name = NULL_TREE;
+  if (!no_overflow
+       && !iv_can_overflow_p (data->current_loop, TREE_TYPE (base),
+                             base, step))
+    no_overflow = true;
   iv->no_overflow = no_overflow;
   iv->have_address_use = false;
 
@@ -1882,8 +1885,8 @@ find_deriving_biv_for_expr (struct ivopts_data *data, tree expr)
       iv = find_deriving_biv_for_expr (data, e2);
       if (iv)
        return iv;
+      gcc_fallthrough ();
 
-      /* Fallthru.  */
     CASE_CONVERT:
       /* Casts are simple.  */
       return find_deriving_biv_for_expr (data, e1);
@@ -2485,14 +2488,14 @@ compute_max_addr_offset (struct iv_use *use)
 
   for (i = width; i > 0; i--)
     {
-      off = ((unsigned HOST_WIDE_INT) 1 << i) - 1;
+      off = (HOST_WIDE_INT_1U << i) - 1;
       XEXP (addr, 1) = gen_int_mode (off, addr_mode);
       if (memory_address_addr_space_p (mem_mode, addr, as))
        break;
 
       /* For some strict-alignment targets, the offset must be naturally
         aligned.  Try an aligned offset if mem_mode is not QImode.  */
-      off = ((unsigned HOST_WIDE_INT) 1 << i);
+      off = (HOST_WIDE_INT_1U << i);
       if (off > GET_MODE_SIZE (mem_mode) && mem_mode != QImode)
        {
          off -= GET_MODE_SIZE (mem_mode);
@@ -3999,7 +4002,7 @@ get_address_cost (bool symbol_present, bool var_present,
 
       for (i = width; i >= 0; i--)
        {
-         off = -((unsigned HOST_WIDE_INT) 1 << i);
+         off = -(HOST_WIDE_INT_1U << i);
          XEXP (addr, 1) = gen_int_mode (off, address_mode);
          if (memory_address_addr_space_p (mem_mode, addr, as))
            break;
@@ -4008,14 +4011,14 @@ get_address_cost (bool symbol_present, bool var_present,
 
       for (i = width; i >= 0; i--)
        {
-         off = ((unsigned HOST_WIDE_INT) 1 << i) - 1;
+         off = (HOST_WIDE_INT_1U << i) - 1;
          XEXP (addr, 1) = gen_int_mode (off, address_mode);
          if (memory_address_addr_space_p (mem_mode, addr, as))
            break;
          /* For some strict-alignment targets, the offset must be naturally
             aligned.  Try an aligned offset if mem_mode is not QImode.  */
          off = mem_mode != QImode
-               ? ((unsigned HOST_WIDE_INT) 1 << i)
+               ? (HOST_WIDE_INT_1U << i)
                    - GET_MODE_SIZE (mem_mode)
                : 0;
          if (off > 0)
@@ -4214,7 +4217,7 @@ get_address_cost (bool symbol_present, bool var_present,
     }
 
   bits = GET_MODE_BITSIZE (address_mode);
-  mask = ~(~(unsigned HOST_WIDE_INT) 0 << (bits - 1) << 1);
+  mask = ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
   offset &= mask;
   if ((offset >> (bits - 1) & 1))
     offset |= ~mask;
@@ -4522,7 +4525,7 @@ split_address_cost (struct ivopts_data *data,
   int unsignedp, reversep, volatilep;
 
   core = get_inner_reference (addr, &bitsize, &bitpos, &toffset, &mode,
-                             &unsignedp, &reversep, &volatilep, false);
+                             &unsignedp, &reversep, &volatilep);
 
   if (toffset != 0
       || bitpos % BITS_PER_UNIT != 0
@@ -5115,7 +5118,7 @@ determine_group_iv_cost_address (struct ivopts_data *data,
 {
   unsigned i;
   bitmap depends_on;
-  bool can_autoinc, first = true;
+  bool can_autoinc;
   iv_inv_expr_ent *inv_expr = NULL;
   struct iv_use *use = group->vuses[0];
   comp_cost sum_cost = no_cost, cost;
@@ -5142,30 +5145,11 @@ determine_group_iv_cost_address (struct ivopts_data *data,
     {
       struct iv_use *next = group->vuses[i];
 
-      /* Compute cost for the first use with different offset to the main
-        use and add it afterwards.  Costs for these uses could be quite
-        different.  Given below uses in a group:
-          use 0  : {base + A + offset_0, step}
-          use 0.1: {base + A + offset_0, step}
-          use 0.2: {base + A + offset_1, step}
-          use 0.3: {base + A + offset_2, step}
-        when we need to compute costs with candidate:
-          cand 1 : {base + B + offset_0, step}
-
-        The first use with different offset is use 0.2, its cost is larger
-        than cost of use 0/0.1 because we need to compute:
-          A - B + offset_1 - offset_0
-          rather than:
-          A - B.  */
-      if (first && next->addr_offset != use->addr_offset)
-       {
-         first = false;
-         cost = get_computation_cost (data, next, cand, true,
-                                      NULL, &can_autoinc, NULL);
-         /* Remove setup cost.  */
-         if (!cost.infinite_cost_p ())
-           cost -= cost.scratch;
-       }
+      /* TODO: We could skip computing cost for sub iv_use when it has the
+        same cost as the first iv_use, but the cost really depends on the
+        offset and where the iv_use is.  */
+       cost = get_computation_cost (data, next, cand, true,
+                                    NULL, &can_autoinc, NULL);
       sum_cost += cost;
     }
   set_group_iv_cost (data, group, cand, sum_cost, depends_on,
@@ -5184,10 +5168,11 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple *at, tree niter,
   aff_tree step, delta, nit;
   struct iv *iv = cand->iv;
   tree type = TREE_TYPE (iv->base);
-  tree steptype = type;
+  tree steptype;
   if (POINTER_TYPE_P (type))
     steptype = sizetype;
-  steptype = unsigned_type_for (type);
+  else
+    steptype = unsigned_type_for (type);
 
   tree_to_aff_combination (iv->step, TREE_TYPE (iv->step), &step);
   aff_combination_convert (&step, steptype);