[LLVMdev] Aliasing of volatile and non-volatile

Dan Gohman dan433584 at gmail.com
Wed Sep 4 15:04:41 PDT 2013


On Wed, Sep 4, 2013 at 2:48 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Wed, Sep 4, 2013 at 2:33 PM, Krzysztof Parzyszek <
> kparzysz at codeaurora.org> wrote:
>
>> A customer has reported a performance problem, which I have eventually
>> tracked down to the following situation:
>>
>> Consider this program:
>>
>> int foo(int *p, volatile int *q, int n) {
>>   int i, s = 0;
>>   for (i = 0; i < n; ++i)
>>     s += *p + *q;
>>   return s;
>> }
>>
>>
>> LLVM's analysis indicates that *p and *q can alias, even though *p is
>> non-volatile whereas *q is volatile.  I don't have the exact section from
>> the C standard, but if I remember correctly, accessing volatile memory via
>> a non-volatile object results in an undefined behavior.
>
>
> Accessing a variable declared as "volatile int" through a non-volatile
> pointer isn't allowed.  Accessing a variable declared as non-volatile "int"
> through a volatile pointer is allowed.
>
> You might be able to reason out that either p and q don't alias, or q
> points to non-volatile memory... but that's substantially more complicated
> than what you're proposing.
>
> (The section in the standard is 6.5p7.)
>

Furthermore, LLVM IR does not have the concept of "volatile variables". In
LLVM IR, operations are volatile, not storage. There are no semantic rules
prohibiting the mixing of volatile and non-volatile accesses.

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130904/76fe7a61/attachment.html>


More information about the llvm-dev mailing list