]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
poly_int: MEM_REF offsets
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 21 Dec 2017 07:02:13 +0000 (07:02 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 21 Dec 2017 07:02:13 +0000 (07:02 +0000)
This patch allows MEM_REF offsets to be polynomial, with mem_ref_offset
now returning a poly_offset_int instead of an offset_int.  The
non-mechanical changes to callers of mem_ref_offset were handled by
previous patches.

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

gcc/
* fold-const.h (mem_ref_offset): Return a poly_offset_int rather
than an offset_int.
* tree.c (mem_ref_offset): Likewise.
(build_simple_mem_ref_loc): Treat MEM_REF offsets as poly_ints.
* builtins.c (get_object_alignment_2): Likewise.
* expr.c (get_inner_reference, expand_expr_real_1): Likewise.
* gimple-fold.c (get_base_constructor): Likewise.
* gimple-ssa-strength-reduction.c (restructure_reference): Likewise.
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref):
Likewise.
* ipa-polymorphic-call.c
(ipa_polymorphic_call_context::ipa_polymorphic_call_context): Likewise.
* ipa-prop.c (compute_complex_assign_jump_func): Likewise.
(get_ancestor_addr_info): Likewise.
* ipa-param-manipulation.c (ipa_get_adjustment_candidate): Likewise.
* match.pd: Likewise.
* tree-data-ref.c (dr_analyze_innermost): Likewise.
* tree-dfa.c (get_addr_base_and_unit_offset_1): Likewise.
* tree-eh.c (tree_could_trap_p): Likewise.
* tree-object-size.c (addr_object_size): Likewise.
* tree-ssa-address.c (copy_ref_info): Likewise.
* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Likewise.
(indirect_refs_may_alias_p): Likewise.
* tree-ssa-sccvn.c (copy_reference_ops_from_ref): Likewise.
* tree-ssa.c (maybe_rewrite_mem_ref_base): Likewise.
(non_rewritable_mem_ref_base): Likewise.
* tree-vect-data-refs.c (vect_check_gather_scatter): Likewise.
* tree-vrp.c (vrp_prop::check_array_ref): Likewise.
* varasm.c (decode_addr_const): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255930 138bc75d-0d04-0410-961f-82ee72b054a4

23 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/expr.c
gcc/fold-const.h
gcc/gimple-fold.c
gcc/gimple-ssa-strength-reduction.c
gcc/gimple-ssa-warn-restrict.c
gcc/ipa-param-manipulation.c
gcc/ipa-polymorphic-call.c
gcc/ipa-prop.c
gcc/match.pd
gcc/tree-data-ref.c
gcc/tree-dfa.c
gcc/tree-eh.c
gcc/tree-object-size.c
gcc/tree-ssa-address.c
gcc/tree-ssa-alias.c
gcc/tree-ssa-sccvn.c
gcc/tree-ssa.c
gcc/tree-vect-data-refs.c
gcc/tree-vrp.c
gcc/tree.c
gcc/varasm.c

index 58da0852dde4e6a71f14abf34d9c3af0d90a2ce6..2bdcde16a21ea4c6b65bad01d0d22fff02151d36 100644 (file)
@@ -1,3 +1,37 @@
+2017-12-21  Richard Sandiford  <richard.sandiford@linaro.org>
+           Alan Hayward  <alan.hayward@arm.com>
+           David Sherwood  <david.sherwood@arm.com>
+
+       * fold-const.h (mem_ref_offset): Return a poly_offset_int rather
+       than an offset_int.
+       * tree.c (mem_ref_offset): Likewise.
+       (build_simple_mem_ref_loc): Treat MEM_REF offsets as poly_ints.
+       * builtins.c (get_object_alignment_2): Likewise.
+       * expr.c (get_inner_reference, expand_expr_real_1): Likewise.
+       * gimple-fold.c (get_base_constructor): Likewise.
+       * gimple-ssa-strength-reduction.c (restructure_reference): Likewise.
+       * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref):
+       Likewise.
+       * ipa-polymorphic-call.c
+       (ipa_polymorphic_call_context::ipa_polymorphic_call_context): Likewise.
+       * ipa-prop.c (compute_complex_assign_jump_func): Likewise.
+       (get_ancestor_addr_info): Likewise.
+       * ipa-param-manipulation.c (ipa_get_adjustment_candidate): Likewise.
+       * match.pd: Likewise.
+       * tree-data-ref.c (dr_analyze_innermost): Likewise.
+       * tree-dfa.c (get_addr_base_and_unit_offset_1): Likewise.
+       * tree-eh.c (tree_could_trap_p): Likewise.
+       * tree-object-size.c (addr_object_size): Likewise.
+       * tree-ssa-address.c (copy_ref_info): Likewise.
+       * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Likewise.
+       (indirect_refs_may_alias_p): Likewise.
+       * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Likewise.
+       * tree-ssa.c (maybe_rewrite_mem_ref_base): Likewise.
+       (non_rewritable_mem_ref_base): Likewise.
+       * tree-vect-data-refs.c (vect_check_gather_scatter): Likewise.
+       * tree-vrp.c (vrp_prop::check_array_ref): Likewise.
+       * varasm.c (decode_addr_const): Likewise.
+
 2017-12-21  Richard Sandiford  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index 0ff0efea908ec2f9833e5ad8affce1cd40be3b3e..753809f2357009a062e5bc7e742d5f2380d9c3d8 100644 (file)
@@ -346,7 +346,7 @@ get_object_alignment_2 (tree exp, unsigned int *alignp,
          bitpos += ptr_bitpos;
          if (TREE_CODE (exp) == MEM_REF
              || TREE_CODE (exp) == TARGET_MEM_REF)
-           bitpos += mem_ref_offset (exp).to_short_addr () * BITS_PER_UNIT;
+           bitpos += mem_ref_offset (exp).force_shwi () * BITS_PER_UNIT;
        }
     }
   else if (TREE_CODE (exp) == STRING_CST)
index 8a1227908faf9887d2f39cd0b448a8c4ebc0d9cb..4e7349e649488dcf3f763e230996663afd0d0b21 100644 (file)
@@ -7197,8 +7197,8 @@ get_inner_reference (tree exp, poly_int64_pod *pbitsize,
              tree off = TREE_OPERAND (exp, 1);
              if (!integer_zerop (off))
                {
-                 offset_int boff, coff = mem_ref_offset (exp);
-                 boff = coff << LOG2_BITS_PER_UNIT;
+                 poly_offset_int boff = mem_ref_offset (exp);
+                 boff <<= LOG2_BITS_PER_UNIT;
                  bit_offset += boff;
                }
              exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
@@ -10222,9 +10222,9 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
           might end up in a register.  */
        if (mem_ref_refers_to_non_mem_p (exp))
          {
-           HOST_WIDE_INT offset = mem_ref_offset (exp).to_short_addr ();
+           poly_int64 offset = mem_ref_offset (exp).force_shwi ();
            base = TREE_OPERAND (base, 0);
-           if (offset == 0
+           if (known_eq (offset, 0)
                && !reverse
                && tree_fits_uhwi_p (TYPE_SIZE (type))
                && (GET_MODE_BITSIZE (DECL_MODE (base))
index 256dc6ffb350d5c89bae401431c41dac1d60da98..b777606b6e9724806ccf40299e00f1b75226b3bc 100644 (file)
@@ -114,7 +114,7 @@ extern tree fold_indirect_ref_loc (location_t, tree);
 extern tree build_simple_mem_ref_loc (location_t, tree);
 #define build_simple_mem_ref(T)\
        build_simple_mem_ref_loc (UNKNOWN_LOCATION, T)
-extern offset_int mem_ref_offset (const_tree);
+extern poly_offset_int mem_ref_offset (const_tree);
 extern tree build_invariant_address (tree, tree, poly_int64);
 extern tree constant_boolean_node (bool, tree);
 extern tree div_if_zero_remainder (const_tree, const_tree);
index 33eae3e1ed11f1ee3036d53908fa5dd2d8e8a2a8..ae2c9a176c6fd44722b37c4b956b8bd35d7ab5c7 100644 (file)
@@ -6346,7 +6346,7 @@ get_base_constructor (tree base, poly_int64_pod *bit_offset,
        {
          if (!tree_fits_shwi_p (TREE_OPERAND (base, 1)))
            return NULL_TREE;
-         *bit_offset += (mem_ref_offset (base).to_short_addr ()
+         *bit_offset += (mem_ref_offset (base).force_shwi ()
                          * BITS_PER_UNIT);
        }
 
index 7d8543c28ca9ca13737137b409fc5781fb2165cf..9eab9a72a7ffeda1dcecb57632fd4dc605ed42a8 100644 (file)
@@ -970,17 +970,19 @@ restructure_reference (tree *pbase, tree *poffset, widest_int *pindex,
   widest_int index = *pindex;
   tree mult_op0, t1, t2, type;
   widest_int c1, c2, c3, c4, c5;
+  offset_int mem_offset;
 
   if (!base
       || !offset
       || TREE_CODE (base) != MEM_REF
+      || !mem_ref_offset (base).is_constant (&mem_offset)
       || TREE_CODE (offset) != MULT_EXPR
       || TREE_CODE (TREE_OPERAND (offset, 1)) != INTEGER_CST
       || wi::umod_floor (index, BITS_PER_UNIT) != 0)
     return false;
 
   t1 = TREE_OPERAND (base, 0);
-  c1 = widest_int::from (mem_ref_offset (base), SIGNED);
+  c1 = widest_int::from (mem_offset, SIGNED);
   type = TREE_TYPE (TREE_OPERAND (base, 1));
 
   mult_op0 = TREE_OPERAND (offset, 0);
index 69992b89bd6250e17880b2ec675250b2b5d4fde2..ac545e4cf67be026ac597fc9343396f7a94cea74 100644 (file)
@@ -349,10 +349,15 @@ builtin_memref::builtin_memref (tree expr, tree size)
 
   if (TREE_CODE (base) == MEM_REF)
     {
-      offset_int off = mem_ref_offset (base);
-      refoff += off;
-      offrange[0] += off;
-      offrange[1] += off;
+      offset_int off;
+      if (mem_ref_offset (base).is_constant (&off))
+       {
+         refoff += off;
+         offrange[0] += off;
+         offrange[1] += off;
+       }
+      else
+       size = NULL_TREE;
       base = TREE_OPERAND (base, 0);
     }
 
index f8610888cd58f4ccbf8b4771e7fb3d4d6b4a1e1a..efa1ea27c669c3e65c83ef9b72a5eb23c99c086a 100644 (file)
@@ -636,7 +636,7 @@ ipa_get_adjustment_candidate (tree **expr, bool *convert,
 
   if (TREE_CODE (base) == MEM_REF)
     {
-      offset += mem_ref_offset (base).to_short_addr () * BITS_PER_UNIT;
+      offset += mem_ref_offset (base).force_shwi () * BITS_PER_UNIT;
       base = TREE_OPERAND (base, 0);
     }
 
index 21ae70bf493e3fae55babd40954b1538f546e96f..78cde86424479afda52ae680ff1685bcc0a08ea1 100644 (file)
@@ -917,9 +917,11 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
            {
              /* We found dereference of a pointer.  Type of the pointer
                 and MEM_REF is meaningless, but we can look futher.  */
-             if (TREE_CODE (base) == MEM_REF)
+             offset_int mem_offset;
+             if (TREE_CODE (base) == MEM_REF
+                 && mem_ref_offset (base).is_constant (&mem_offset))
                {
-                 offset_int o = mem_ref_offset (base) * BITS_PER_UNIT;
+                 offset_int o = mem_offset * BITS_PER_UNIT;
                  o += offset;
                  o += offset2;
                  if (!wi::fits_shwi_p (o))
index 071c0d69a20ea4c20c8e0ca3a8e086300557784e..7ac250a0a6a8195e7471b83e6c19182fdc1f1f71 100644 (file)
@@ -1267,9 +1267,12 @@ compute_complex_assign_jump_func (struct ipa_func_body_info *fbi,
   if (TREE_CODE (TREE_TYPE (op1)) != RECORD_TYPE)
     return;
   base = get_ref_base_and_extent_hwi (op1, &offset, &size, &reverse);
-  if (!base || TREE_CODE (base) != MEM_REF)
+  offset_int mem_offset;
+  if (!base
+      || TREE_CODE (base) != MEM_REF
+      || !mem_ref_offset (base).is_constant (&mem_offset))
     return;
-  offset += mem_ref_offset (base).to_short_addr () * BITS_PER_UNIT;
+  offset += mem_offset.to_short_addr () * BITS_PER_UNIT;
   ssa = TREE_OPERAND (base, 0);
   if (TREE_CODE (ssa) != SSA_NAME
       || !SSA_NAME_IS_DEFAULT_DEF (ssa)
@@ -1311,7 +1314,10 @@ get_ancestor_addr_info (gimple *assign, tree *obj_p, HOST_WIDE_INT *offset)
   obj = expr;
   expr = get_ref_base_and_extent_hwi (expr, offset, &size, &reverse);
 
-  if (!expr || TREE_CODE (expr) != MEM_REF)
+  offset_int mem_offset;
+  if (!expr
+      || TREE_CODE (expr) != MEM_REF
+      || !mem_ref_offset (expr).is_constant (&mem_offset))
     return NULL_TREE;
   parm = TREE_OPERAND (expr, 0);
   if (TREE_CODE (parm) != SSA_NAME
@@ -1319,7 +1325,7 @@ get_ancestor_addr_info (gimple *assign, tree *obj_p, HOST_WIDE_INT *offset)
       || TREE_CODE (SSA_NAME_VAR (parm)) != PARM_DECL)
     return NULL_TREE;
 
-  *offset += mem_ref_offset (expr).to_short_addr () * BITS_PER_UNIT;
+  *offset += mem_offset.to_short_addr () * BITS_PER_UNIT;
   *obj_p = obj;
   return expr;
 }
index ec99250f1c5ca403814006792c0754f378b534cb..bd1673ac5e978aa66575c0d356f1e347b0768857 100644 (file)
@@ -3561,12 +3561,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      tree base1 = get_addr_base_and_unit_offset (TREE_OPERAND (@1, 0), &off1);
      if (base0 && TREE_CODE (base0) == MEM_REF)
        {
-        off0 += mem_ref_offset (base0).to_short_addr ();
+        off0 += mem_ref_offset (base0).force_shwi ();
          base0 = TREE_OPERAND (base0, 0);
        }
      if (base1 && TREE_CODE (base1) == MEM_REF)
        {
-         off1 += mem_ref_offset (base1).to_short_addr ();
+        off1 += mem_ref_offset (base1).force_shwi ();
          base1 = TREE_OPERAND (base1, 0);
        }
    }
index 86a587d04c0559eced40438c1649fa52a7bcd20a..2707cf82ebafff7f691d007f35ea63fcf195e71d 100644 (file)
@@ -820,16 +820,16 @@ dr_analyze_innermost (innermost_loop_behavior *drb, tree ref,
     }
 
   /* Calculate the alignment and misalignment for the inner reference.  */
-  unsigned int HOST_WIDE_INT base_misalignment;
-  unsigned int base_alignment;
-  get_object_alignment_1 (base, &base_alignment, &base_misalignment);
+  unsigned int HOST_WIDE_INT bit_base_misalignment;
+  unsigned int bit_base_alignment;
+  get_object_alignment_1 (base, &bit_base_alignment, &bit_base_misalignment);
 
   /* There are no bitfield references remaining in BASE, so the values
      we got back must be whole bytes.  */
-  gcc_assert (base_alignment % BITS_PER_UNIT == 0
-             && base_misalignment % BITS_PER_UNIT == 0);
-  base_alignment /= BITS_PER_UNIT;
-  base_misalignment /= BITS_PER_UNIT;
+  gcc_assert (bit_base_alignment % BITS_PER_UNIT == 0
+             && bit_base_misalignment % BITS_PER_UNIT == 0);
+  unsigned int base_alignment = bit_base_alignment / BITS_PER_UNIT;
+  poly_int64 base_misalignment = bit_base_misalignment / BITS_PER_UNIT;
 
   if (TREE_CODE (base) == MEM_REF)
     {
@@ -837,8 +837,8 @@ dr_analyze_innermost (innermost_loop_behavior *drb, tree ref,
        {
          /* Subtract MOFF from the base and add it to POFFSET instead.
             Adjust the misalignment to reflect the amount we subtracted.  */
-         offset_int moff = mem_ref_offset (base);
-         base_misalignment -= moff.to_short_addr ();
+         poly_offset_int moff = mem_ref_offset (base);
+         base_misalignment -= moff.force_shwi ();
          tree mofft = wide_int_to_tree (sizetype, moff);
          if (!poffset)
            poffset = mofft;
@@ -925,8 +925,14 @@ dr_analyze_innermost (innermost_loop_behavior *drb, tree ref,
   drb->offset = fold_convert (ssizetype, offset_iv.base);
   drb->init = init;
   drb->step = step;
-  drb->base_alignment = base_alignment;
-  drb->base_misalignment = base_misalignment & (base_alignment - 1);
+  if (known_misalignment (base_misalignment, base_alignment,
+                         &drb->base_misalignment))
+    drb->base_alignment = base_alignment;
+  else
+    {
+      drb->base_alignment = known_alignment (base_misalignment);
+      drb->base_misalignment = 0;
+    }
   drb->offset_alignment = highest_pow2_factor (offset_iv.base);
   drb->step_alignment = highest_pow2_factor (step);
 
index 681afbcd05646ecf1df5bfe6789cfa3ce558ba6c..3358763b466ee8d686fbb1fdf08b1b5f22378e71 100644 (file)
@@ -798,8 +798,8 @@ get_addr_base_and_unit_offset_1 (tree exp, poly_int64_pod *poffset,
              {
                if (!integer_zerop (TREE_OPERAND (exp, 1)))
                  {
-                   offset_int off = mem_ref_offset (exp);
-                   byte_offset += off.to_short_addr ();
+                   poly_offset_int off = mem_ref_offset (exp);
+                   byte_offset += off.force_shwi ();
                  }
                exp = TREE_OPERAND (base, 0);
              }
@@ -820,8 +820,8 @@ get_addr_base_and_unit_offset_1 (tree exp, poly_int64_pod *poffset,
                  return NULL_TREE;
                if (!integer_zerop (TMR_OFFSET (exp)))
                  {
-                   offset_int off = mem_ref_offset (exp);
-                   byte_offset += off.to_short_addr ();
+                   poly_offset_int off = mem_ref_offset (exp);
+                   byte_offset += off.force_shwi ();
                  }
                exp = TREE_OPERAND (base, 0);
              }
index 65e850d36ad254758ee05989c3d52e3e95c17359..fc5fb02ddcd52e8653b47126f8e3a591426af5c9 100644 (file)
@@ -2658,14 +2658,15 @@ tree_could_trap_p (tree expr)
       if (TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR)
        {
          tree base = TREE_OPERAND (TREE_OPERAND (expr, 0), 0);
-         offset_int off = mem_ref_offset (expr);
-         if (wi::neg_p (off, SIGNED))
+         poly_offset_int off = mem_ref_offset (expr);
+         if (maybe_lt (off, 0))
            return true;
          if (TREE_CODE (base) == STRING_CST)
-           return wi::leu_p (TREE_STRING_LENGTH (base), off);
-         else if (DECL_SIZE_UNIT (base) == NULL_TREE
-                  || TREE_CODE (DECL_SIZE_UNIT (base)) != INTEGER_CST
-                  || wi::leu_p (wi::to_offset (DECL_SIZE_UNIT (base)), off))
+           return maybe_le (TREE_STRING_LENGTH (base), off);
+         tree size = DECL_SIZE_UNIT (base);
+         if (size == NULL_TREE
+             || !poly_int_tree_p (size)
+             || maybe_le (wi::to_poly_offset (size), off))
            return true;
          /* Now we are sure the first byte of the access is inside
             the object.  */
index 14cb435f07f401db9b56db8fb019631a8f6b39e6..488676e4d20dad8381bb5f9b2935d1f947354f8d 100644 (file)
@@ -210,11 +210,17 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
        }
       if (sz != unknown[object_size_type])
        {
-         offset_int dsz = wi::sub (sz, mem_ref_offset (pt_var));
-         if (wi::neg_p (dsz))
-           sz = 0;
-         else if (wi::fits_uhwi_p (dsz))
-           sz = dsz.to_uhwi ();
+         offset_int mem_offset;
+         if (mem_ref_offset (pt_var).is_constant (&mem_offset))
+           {
+             offset_int dsz = wi::sub (sz, mem_offset);
+             if (wi::neg_p (dsz))
+               sz = 0;
+             else if (wi::fits_uhwi_p (dsz))
+               sz = dsz.to_uhwi ();
+             else
+               sz = unknown[object_size_type];
+           }
          else
            sz = unknown[object_size_type];
        }
index 440215b7818f2c50c1a04ead2bbc3c78edd72868..87df1238bfa57462acc7c2eb4d97803cff81e38d 100644 (file)
@@ -1008,8 +1008,8 @@ copy_ref_info (tree new_ref, tree old_ref)
                           && (TREE_INT_CST_LOW (TMR_STEP (new_ref))
                               < align)))))
            {
-             unsigned int inc = (mem_ref_offset (old_ref).to_short_addr ()
-                                 - mem_ref_offset (new_ref).to_short_addr ());
+             poly_uint64 inc = (mem_ref_offset (old_ref)
+                                - mem_ref_offset (new_ref)).force_uhwi ();
              adjust_ptr_info_misalignment (new_pi, inc);
            }
          else
index 2f8ff40f04268dde35d4c9698f6a795e0be594ed..7601b19408cdbca9ef6ad2e363bbb08206837707 100644 (file)
@@ -1139,7 +1139,7 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
                       && DECL_P (base2));
 
   ptr1 = TREE_OPERAND (base1, 0);
-  offset_int moff = mem_ref_offset (base1) << LOG2_BITS_PER_UNIT;
+  poly_offset_int moff = mem_ref_offset (base1) << LOG2_BITS_PER_UNIT;
 
   /* If only one reference is based on a variable, they cannot alias if
      the pointer access is beyond the extent of the variable access.
@@ -1295,8 +1295,8 @@ indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
                      && operand_equal_p (TMR_INDEX2 (base1),
                                          TMR_INDEX2 (base2), 0))))))
     {
-      offset_int moff1 = mem_ref_offset (base1) << LOG2_BITS_PER_UNIT;
-      offset_int moff2 = mem_ref_offset (base2) << LOG2_BITS_PER_UNIT;
+      poly_offset_int moff1 = mem_ref_offset (base1) << LOG2_BITS_PER_UNIT;
+      poly_offset_int moff2 = mem_ref_offset (base2) << LOG2_BITS_PER_UNIT;
       return ranges_maybe_overlap_p (offset1 + moff1, max_size1,
                                     offset2 + moff2, max_size2);
     }
index 89ef26c7a3f616dc46e72b27a2b585300b9eba50..7146f8f7e2dc773f06c8923272dd3a72ad52f297 100644 (file)
@@ -766,11 +766,8 @@ copy_reference_ops_from_ref (tree ref, vec<vn_reference_op_s> *result)
        case MEM_REF:
          /* The base address gets its own vn_reference_op_s structure.  */
          temp.op0 = TREE_OPERAND (ref, 1);
-           {
-             offset_int off = mem_ref_offset (ref);
-             if (wi::fits_shwi_p (off))
-               temp.off = off.to_shwi ();
-           }
+         if (!mem_ref_offset (ref).to_shwi (&temp.off))
+           temp.off = -1;
          temp.clique = MR_DEPENDENCE_CLIQUE (ref);
          temp.base = MR_DEPENDENCE_BASE (ref);
          temp.reverse = REF_REVERSE_STORAGE_ORDER (ref);
index 151f544babada65f208cf26e21f63e1f6d75514b..c04e0cc6dbf9259219338aba11891000374f439e 100644 (file)
@@ -1379,10 +1379,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
        }
       else if (DECL_SIZE (sym)
               && TREE_CODE (DECL_SIZE (sym)) == INTEGER_CST
-              && mem_ref_offset (*tp) >= 0
-              && wi::leu_p (mem_ref_offset (*tp)
-                            + wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
-                            wi::to_offset (DECL_SIZE_UNIT (sym)))
+              && (known_subrange_p
+                  (mem_ref_offset (*tp),
+                   wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
+                   0, wi::to_offset (DECL_SIZE_UNIT (sym))))
               && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp)) 
                   || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp)))
                       == TYPE_PRECISION (TREE_TYPE (*tp))))
@@ -1433,9 +1433,8 @@ non_rewritable_mem_ref_base (tree ref)
           || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
          && useless_type_conversion_p (TREE_TYPE (base),
                                        TREE_TYPE (TREE_TYPE (decl)))
-         && wi::fits_uhwi_p (mem_ref_offset (base))
-         && wi::gtu_p (wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
-                       mem_ref_offset (base))
+         && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
+                      mem_ref_offset (base))
          && multiple_of_p (sizetype, TREE_OPERAND (base, 1),
                            TYPE_SIZE_UNIT (TREE_TYPE (base))))
        return NULL_TREE;
@@ -1445,11 +1444,10 @@ non_rewritable_mem_ref_base (tree ref)
        return NULL_TREE;
       /* For integral typed extracts we can use a BIT_FIELD_REF.  */
       if (DECL_SIZE (decl)
-         && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
-         && mem_ref_offset (base) >= 0
-         && wi::leu_p (mem_ref_offset (base)
-                       + wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
-                       wi::to_offset (DECL_SIZE_UNIT (decl)))
+         && (known_subrange_p
+             (mem_ref_offset (base),
+              wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
+              0, wi::to_poly_offset (DECL_SIZE_UNIT (decl))))
          /* ???  We can't handle bitfield precision extracts without
             either using an alternate type for the BIT_FIELD_REF and
             then doing a conversion or possibly adjusting the offset
index 9867077cd86a002c8eb262fe52073bda6b42eeda..7d039185446915557b574fe90437f076db375b26 100644 (file)
@@ -3276,10 +3276,7 @@ vect_check_gather_scatter (gimple *stmt, loop_vec_info loop_vinfo,
       if (!integer_zerop (TREE_OPERAND (base, 1)))
        {
          if (off == NULL_TREE)
-           {
-             offset_int moff = mem_ref_offset (base);
-             off = wide_int_to_tree (sizetype, moff);
-           }
+           off = wide_int_to_tree (sizetype, mem_ref_offset (base));
          else
            off = size_binop (PLUS_EXPR, off,
                              fold_convert (sizetype, TREE_OPERAND (base, 1)));
index 9940f5012a18dc3e9e0e3caa7f490b8e64f1fdc2..27f7c37cbd7f7b9fd02b1362da1d6ec10a54675f 100644 (file)
@@ -4952,7 +4952,9 @@ vrp_prop::search_for_addr_array (tree t, location_t location)
          || TREE_CODE (el_sz) != INTEGER_CST)
        return;
 
-      idx = mem_ref_offset (t);
+      if (!mem_ref_offset (t).is_constant (&idx))
+       return;
+
       idx = wi::sdiv_trunc (idx, wi::to_offset (el_sz));
       if (idx < 0)
        {
@@ -5266,7 +5268,6 @@ remove_range_assertions (void)
       }
 }
 
-
 /* Return true if STMT is interesting for VRP.  */
 
 bool
index 400c5c7895e9c238dcfe395f78bf4490382a5f81..97c9f815039b1333e59e32a8b925fd49951b07a0 100644 (file)
@@ -4840,7 +4840,7 @@ build_simple_mem_ref_loc (location_t loc, tree ptr)
       gcc_assert (ptr);
       if (TREE_CODE (ptr) == MEM_REF)
        {
-         offset += mem_ref_offset (ptr).to_short_addr ();
+         offset += mem_ref_offset (ptr).force_shwi ();
          ptr = TREE_OPERAND (ptr, 0);
        }
       else
@@ -4855,10 +4855,11 @@ build_simple_mem_ref_loc (location_t loc, tree ptr)
 
 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T.  */
 
-offset_int
+poly_offset_int
 mem_ref_offset (const_tree t)
 {
-  return offset_int::from (wi::to_wide (TREE_OPERAND (t, 1)), SIGNED);
+  return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
+                               SIGNED);
 }
 
 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
index 2b2cde972700fe8f4a002995f96cefad58ed5d3a..28e35ff6c3e9fa142c7512eb5afac82ef1d9092c 100644 (file)
@@ -2904,7 +2904,7 @@ decode_addr_const (tree exp, struct addr_const *value)
       else if (TREE_CODE (target) == MEM_REF
               && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
        {
-         offset += mem_ref_offset (target).to_short_addr ();
+         offset += mem_ref_offset (target).force_shwi ();
          target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
        }
       else if (TREE_CODE (target) == INDIRECT_REF