public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* vect: Make vect_check_gather_scatter reject offsets that aren't multiples of BITS_PER_UNIT [PR107346]
@ 2022-10-21 16:42 Andre Vieira (lists)
  2022-10-24  7:17 ` Richard Biener
  0 siblings, 1 reply; 9+ messages in thread
From: Andre Vieira (lists) @ 2022-10-21 16:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Biener, Richard Sandiford, ebotcazou

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

Hi,

The ada failure reported in the PR was being caused by 
vect_check_gather_scatter failing to deal with bit offsets that weren't 
multiples of BITS_PER_UNIT. This patch makes vect_check_gather_scatter 
reject memory accesses with such offsets.

Bootstrapped and regression tested on aarch64 and x86_64.

I wasn't sure whether I should add a new Ada test that shows the same 
failure without the bitfield lowering, I suspect this is such a rare 
form of data-structure that is why no other tests have highlighted the 
failure. Let me know if you would like me to add it still, the change is 
quite simple, just change the Int24 -> Int32 type in the structure. The 
'thing' that causes the failure is the 4-bit member inside the packed 
structure before the field we access, giving it a 4-bit offset. I 
attempted but failed to create a C test using __attribute__((packed)).

Kind Regards,
Andre

gcc/ChangeLog:

         PR tree-optimization/107346
         * tree-vect-data-refs.cc (vect_check_gather_scatter): Reject 
offsets that aren't
         multiples of BITS_PER_UNIT.

[-- Attachment #2: pr107346.patch --]
[-- Type: text/plain, Size: 689 bytes --]

diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 4a23d6172aaa12ad7049dc626e5c4afbd5ca3f74..6c892791bd4c39f672add4e4c22a9d7835e292d6 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -4016,6 +4016,11 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
   if (reversep)
     return false;
 
+  /* PR 107346.  Packed structs can have fields at offsets that are not
+     multiples of BITS_PER_UNIT.  Do not use gather/scatters in such cases.  */
+  if (!multiple_p (pbitpos, BITS_PER_UNIT))
+    return false;
+
   poly_int64 pbytepos = exact_div (pbitpos, BITS_PER_UNIT);
 
   if (TREE_CODE (base) == MEM_REF)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-28 13:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 16:42 vect: Make vect_check_gather_scatter reject offsets that aren't multiples of BITS_PER_UNIT [PR107346] Andre Vieira (lists)
2022-10-24  7:17 ` Richard Biener
2022-10-24  8:31   ` Eric Botcazou
2022-10-24 10:31   ` Andre Vieira (lists)
2022-10-24 12:46     ` Richard Biener
2022-10-24 13:24       ` Andre Vieira (lists)
2022-10-24 13:29         ` Richard Biener
2022-10-28 13:43           ` Andre Vieira (lists)
2022-10-28 13:46             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).