[LLVMdev] Aliasing of volatile and non-volatile

Krzysztof Parzyszek kparzysz at codeaurora.org
Sat Sep 7 06:25:46 PDT 2013


On 9/7/2013 3:23 AM, James Courtier-Dutton wrote:
> Are you sure this is an alias problem?

In principle no, but in some sense yes---it's related to the way 
AliasSetTracker treats volatile references.


> but GCC is changing to code to look like this:
>
> int foo(int *p, volatile int *q, int n) {
>    int i, s = 0;
>    int t;
>    t = *p;
>    for (i = 0; i < n; ++i)
>      s += t + *q;
>    return s;
> }
>
> GCC is raising the *p out of the loop, recognizing the fact that memory
> access is more expensive than reg access.
> What is preventing LLVM from doing the same?

When a volatile load is added to an AliasSetTracker, the alias set 
associated with the load's memory location is marked as "mod/ref".  This 
means that even if the alias set only contains loads (i.e. is "ref" but 
not "mod"), then after adding a volatile load it will become
"mod" as well.  This will prevent any load from being moved out of a 
loop in LICM, since LICM uses AST to see if the load's location has been 
changed in the loop.

I have posted a patch on the llvm-commits mailing list:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130902/187072.html

-K

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation



More information about the llvm-dev mailing list