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 via email to