Limit qualifier in attribute C vs noalias in LLVM IR

my question is related to the different semantics of the qualifier restrict in C and the noalias attribute in LLVM when they are used as functional parameters.

According to the LLVM documentation for noalias :

This indicates that objects accessed through pointer values โ€‹โ€‹based on the argument or return value are also not accessed at run time through pointer values โ€‹โ€‹not based on the argument or return value.

In the case of the restrict qualifier, the C11 project (example 3, p. 1212, section 6.7.3.1) sets an example where there is smoothing between the two arguments to restrict , which is fine if they only read data:

void h(int n, int * restrict p, int * restrict q, int * restrict r) { int i; for (i = 0; i < n; i++) p[i] = q[i] + r[i]; } 

It seems to me that the above example does not satisfy the semantics of noalias . Is that the case?

+6
source share
1 answer

As Jens Gustedt suggested, digging in the links led me to the AliasAnalysis page, which states:

The most obvious example is when two pointers point to non-overlapping ranges of memory. Another thing is when two pointers are used only for reading memory. Another is that the memory is freed and redistributed between calls through one pointer and accessed through another - in this case there is a dependency, but it is mediated by free and redistribution.

This solves the question: the noalias attribute noalias equivalent to the C restrict qualifier in the function parameters.

0
source

Source: https://habr.com/ru/post/1011663/


All Articles