[llvm-dev] Given one restrict pointer based on another, should they never alias?

Alexey Zhikhartsev via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 14 13:52:20 PST 2020


We recently found an issue when using the full restrict implementation
developed by Jeroen; it surfaces when compiling an obscure combination of
std::valarray and std::indirect_array but I don't want to bore you with all
the details. What it boils down to is this basic question about restrict:

Given one restrict pointer based on another, should they never alias?

As far as I understand the formal definition of "restrict" in section
6.7.3.1 of the C standard [1], in the function below, pointer `y` is based
on "restrict" pointer `x`; hence, the compiler will assume that accesses *x
and *y might alias:

void assign1(int *pA, long N) {
  int *restrict x = pA;
  {
    int *y = x + N;
    *x = *y;
  }
}


However, what if y itself is declared "restrict": can the compiler assume
that *x and *y will never alias?

void assign2(int *pA, long N) {
  int *restrict x = pA;
  {
    int *restrict y = x + N;
    *x = *y;
  }
}

Both Jeroen's and Hal's implementation (the intrinsic-based one) will say
"NoAlias" for the accesses in assign2() but shouldn't x and y be in the
same restrictness "bucket" since y is based on x?

[1] http://port70.net/~nsz/c/c11/n1570.html#6.7.3.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200214/f91a6da6/attachment.html>


More information about the llvm-dev mailing list