Skip to content

LoadChainSeparation wrongly diverts memory state edges #1804

Description

@phate

Consider the following C program:

#include <stdio.h>
#include <unistd.h>

static int
correct_optind(int argc, char **argv)
{
  int option;

  optind = 1;
  opterr = 0;
  while ((option = getopt(argc, argv, "v")) != -1)
    ;

  return optind;
}

int
main(int argc, char **argv)
{
  int correct = correct_optind(argc, argv);

  printf("correct optind: %d (argv[%d] is the first non-option)\n",
         correct, correct);
  return 0;
}

which is compiled with: -JAAAndersenRegionAware -JStoreValueForwarding -JLoadChainSeparation -JNodeReduction

Here is a graph from directly before the LoadChainSeparation pass:

Image

The load node after the loop has memory state dependency to the loop, as the loop contains a call to the external function getopt()

Here is the same graph directly after the LoadChainSeparation pass:

Image

The load node has all in a sudden no memory state edge dependency towards the loop any longer. If the IOBarrier would be removed now (which is legal to do), then the load would be independent of the theta node and therefore could be scheduled before it. This is incorrect.

optind.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions