[LLVMdev] Aliasing of volatile and non-volatile

James Courtier-Dutton james.dutton at gmail.com
Sat Sep 7 02:04:01 PDT 2013


On 4 September 2013 22:33, 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.  This would suggest
> that volatiles and non-volatiles may be considered not to alias
> automatically, even if TBAA would not be able to prove it.
>
>
Could the problem also be looked at like this:
1) If *p and *q are aliased, the results of *p is undefined.
2) If *p and *q and not aliased, the results of *p is defined.
Surely, in this sort of situation, optimizations should should be done
assuming (2), because if the case is (1) the result it undefined, so doing
(2) won't change that.

Kind Regards

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130907/c77df181/attachment.html>


More information about the llvm-dev mailing list