poly_int: get_object_alignment_2
authorRichard Sandiford <richard.sandiford@linaro.org>
Wed, 20 Dec 2017 12:56:32 +0000 (12:56 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 20 Dec 2017 12:56:32 +0000 (12:56 +0000)
This patch makes get_object_alignment_2 track polynomial offsets
and sizes.  The real work is done by get_inner_reference, but we
then need to handle the alignment correctly.

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

gcc/
* builtins.c (get_object_alignment_2): Track polynomial offsets
and sizes.  Update the alignment handling.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>
From-SVN: r255893

gcc/ChangeLog
gcc/builtins.c

index 3aca9c59ccd5de472136f775b833d7ac9ff2e337..c0c6c81b572da1a464e55ad17c52ef47f42b2d27 100644 (file)
@@ -1,3 +1,10 @@
+2017-12-20  Richard Sandiford  <richard.sandiford@linaro.org>
+           Alan Hayward  <alan.hayward@arm.com>
+           David Sherwood  <david.sherwood@arm.com>
+
+       * builtins.c (get_object_alignment_2): Track polynomial offsets
+       and sizes.  Update the alignment handling.
+
 2017-12-20  Richard Sandiford  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index 3e8ea95d729ae17021dae40cda49f4b150b1bd20..277bbe8db269d69791251a66d49ecff8e0d9e43a 100644 (file)
@@ -248,7 +248,7 @@ static bool
 get_object_alignment_2 (tree exp, unsigned int *alignp,
                        unsigned HOST_WIDE_INT *bitposp, bool addr_p)
 {
-  HOST_WIDE_INT bitsize, bitpos;
+  poly_int64 bitsize, bitpos;
   tree offset;
   machine_mode mode;
   int unsignedp, reversep, volatilep;
@@ -373,8 +373,17 @@ get_object_alignment_2 (tree exp, unsigned int *alignp,
        }
     }
 
+  /* Account for the alignment of runtime coefficients, so that the constant
+     bitpos is guaranteed to be accurate.  */
+  unsigned int alt_align = ::known_alignment (bitpos - bitpos.coeffs[0]);
+  if (alt_align != 0 && alt_align < align)
+    {
+      align = alt_align;
+      known_alignment = false;
+    }
+
   *alignp = align;
-  *bitposp = bitpos & (*alignp - 1);
+  *bitposp = bitpos.coeffs[0] & (align - 1);
   return known_alignment;
 }