public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pcordes at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/84508] Load of misaligned address using _mm_load_sd
Date: Thu, 30 May 2024 18:38:03 +0000	[thread overview]
Message-ID: <bug-84508-4-tp6pqRj0Qg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-84508-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84508

--- Comment #27 from Peter Cordes <pcordes at gmail dot com> ---
(In reply to Hongtao Liu from comment #26)
> (In reply to Hongtao Liu from comment #25)
> > (In reply to Peter Cordes from comment #22)
> > > Why are we adding an alignment requirement to _mm_storel_pd, the intrinsic
> > > for MOVLPD?
> > > 
> > From Intel intrinsic guide[1], there's explict "mem_addr does not need to be
> > aligned on any particular boundary" for mm_store_sd, but not for
> > _mm_storel_pd.
> > [1] https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html
> > 
> But for mm_loadl_pd, it also says no need for alignment, I need to confirm
> with my peers if there's any specific purpose on that.
> And yes, for <16-byte memory access, there's no alignment requirement
> functionally.

Interesting, yes some entries explicitly say the memory can be unaligned, some
don't.  But I don't think we should read that as alignment required being the
default if not stated.  Every intrinsic that does require alignment explicitly
says so.  (Like _mm_load_si128.)  We could make the same argument in the other
direction, that if an alignment requirement isn't mentioned, we should assume
there isn't one.

And I already posted earlier about why we shouldn't assume C semantics based on
the pointer type as Andrew Pinski had thought.  Intel's intrinsic docs were
originally written for ICC (classic), which takes intrinsics very literally: an
intrinsic in the C source will (almost?) always compile to the corresponding
asm instruction.  And presumably not optimizing based on pointer-alignment UB
even on a deref.  And definitely not on strict-aliasing UB.

So the C defaults for deref of a double* or __m64* shouldn't be assumed even
when the docs don't say anything about alignment.  They also don't mention
aliasing but we know from Intel's examples of how to use intrinsics (I think)
that the load/store intrinsics are all may_alias accesses.

Intel's current ICX compiler is based on LLVM which does care about aliasing
and alignment UB when optimizing, but their intrinsic docs still read like
they're thinking more in terms of asm than in terms of the C abstract machine. 
Probably they haven't been rewritten with that in mind since they implement
them (in their own compilers) so they Just Work even when aliasing other types
or without alignment.

      parent reply	other threads:[~2024-05-30 18:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-84508-4@http.gcc.gnu.org/bugzilla/>
2021-05-17  8:08 ` jakub at gcc dot gnu.org
2022-03-26 23:35 ` peter at cordes dot ca
2022-03-28  1:59 ` crazylht at gmail dot com
2022-03-28  2:09 ` pinskia at gcc dot gnu.org
2022-03-28  7:23 ` peter at cordes dot ca
2023-12-17 23:21 ` pinskia at gcc dot gnu.org
2024-05-09  7:43 ` cvs-commit at gcc dot gnu.org
2024-05-09  8:55 ` liuhongt at gcc dot gnu.org
2024-05-09 19:02 ` cvs-commit at gcc dot gnu.org
2024-05-29 18:45 ` pcordes at gmail dot com
2024-05-29 19:01 ` noloader at gmail dot com
2024-05-29 19:13 ` pcordes at gmail dot com
2024-05-30  6:01 ` liuhongt at gcc dot gnu.org
2024-05-30  6:33 ` liuhongt at gcc dot gnu.org
2024-05-30 18:38 ` pcordes at gmail dot com [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-84508-4-tp6pqRj0Qg@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).