public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/110499] New: malloc branch predictor is broken
Date: Fri, 30 Jun 2023 13:53:01 +0000	[thread overview]
Message-ID: <bug-110499-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110499
           Summary: malloc branch predictor is broken
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

Malloc branch predictor currently predicts that malloc() call likely returns 1.
This is good for NULL pointer checks, but not good for checking pointers for
equality:

#include <malloc.h>
void
test()
{
         if (malloc(10) == malloc(20))
                 printf ("Impossible!\n");
}

gets predicted as:

void test ()
{
  void * _1;
  void * _2;

  <bb 2> [local count: 1073741824]:
  _1 = malloc (10);
  _2 = malloc (20);
  if (_1 == _2)
    goto <bb 3>; [99.96%]
  else
    goto <bb 4>; [0.04%]

  <bb 3> [local count: 1073312329]:
  __builtin_puts (&"Impossible!"[0]);

  <bb 4> [local count: 1073741824]:
  return;

}

So we think that Impossible is output with 99.96 probability.

             reply	other threads:[~2023-06-30 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30 13:53 hubicka at gcc dot gnu.org [this message]
2023-07-01 20:53 ` [Bug tree-optimization/110499] " pinskia 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-110499-4@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).