public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pc at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/104901] gcc/config/rs6000/mm_malloc.h:46: incorrectLogicOperator
Date: Mon, 21 Mar 2022 18:22:46 +0000	[thread overview]
Message-ID: <bug-104901-4-AiOLg5LT5Q@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104901-4@http.gcc.gnu.org/bugzilla/>

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

pc at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pc at gcc dot gnu.org

--- Comment #5 from pc at gcc dot gnu.org ---
(In reply to Segher Boessenkool from comment #4)
> is this micro-optimisation useful at all, don't
> posix_memalign and malloc end up the same under the covers anyway?

posix_memalign returns memory aligned to a specified power-of-2 alignment.
malloc returns memory aligned to some ABI minimum. (You already know this, I'm
sure.) The code will use malloc if it can, and posix_memalign otherwise. There
may be a slight advantage to using malloc instead of posix_memalign. The paths
are indeed different. I'm not sure why the floor is raised after determining
not to call malloc:
--
  if (__alignment == __malloc_align && __alignment == __vec_align)
    return malloc (__size);
  if (__alignment < __vec_align)
    __alignment = __vec_align;
--
(I probably would've written the code slightly differently.)

It appears to me that the identified code would be always false on a 32-bit
system, where __malloc_align would be computed as 64 bits, and _vec_align as
128 bits.  It would be always true on a 64-bit system (128 == 128).

All that being said, I'm not sure I see any problem with the code, and maybe
the analyzer is being a bit overzealous?

FWIW, the code was likely taken as an analog to gcc/config/i386/pmm_malloc.h:
--
  if (__alignment == 1)
    return malloc (__size);
  if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4))
    __alignment = sizeof (void *);
  if (posix_memalign (&__ptr, __alignment, __size) == 0)
    return __ptr;
--

  parent reply	other threads:[~2022-03-21 18:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13 13:44 [Bug target/104901] New: " dcb314 at hotmail dot com
2022-03-13 13:47 ` [Bug target/104901] " dcb314 at hotmail dot com
2022-03-13 14:10 ` schwab@linux-m68k.org
2022-03-14  8:44 ` rguenth at gcc dot gnu.org
2022-03-18 14:28 ` segher at gcc dot gnu.org
2022-03-21 18:22 ` pc at gcc dot gnu.org [this message]
2022-03-21 18:49 ` segher at gcc dot gnu.org
2022-03-21 19:00 ` schwab@linux-m68k.org
2022-03-21 19:28 ` segher at gcc dot gnu.org
2022-03-21 19:33 ` dcb314 at hotmail dot com
2022-03-21 19:53 ` schwab@linux-m68k.org
2022-03-21 20:23 ` segher at gcc dot gnu.org

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-104901-4-AiOLg5LT5Q@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).