[LLVMdev] Aliasing confusion
andrew adams
andrew.b.adams at gmail.com
Fri Oct 7 15:22:01 PDT 2011
On Fri, Oct 7, 2011 at 5:43 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Fri, Oct 7, 2011 at 2:15 PM, andrew adams <andrew.b.adams at gmail.com> wrote:
>> Hi all,
>>
>> I'm having trouble understanding how llvm determines if pointers
>> alias. Consider the following two functions that each do a redundant
>> load:
>>
>> define float @A(float * noalias %ptr1) {
>> %ptr2 = getelementptr float* %ptr1, i32 1024
>> %val1a = load float* %ptr1
>> store float %val1a, float* %ptr2
>> %val1b = load float* %ptr1
>> ret float %val1b
>> }
>>
>>
>> define float @B(float * noalias %ptr1, float * noalias %ptr2) {
>> %val1a = load float* %ptr1
>> store float %val1a, float* %ptr2
>> %val1b = load float* %ptr1
>> ret float %val1b
>> }
>>
>> When I throw this code into test_alias.ll and run:
>>
>> opt test_alias.ll -basicaa -print-alias-sets > /dev/null
>>
>> it tells me that in the first function, ptr1 and ptr2 may alias, and
>> in the second function they do not. The source of
>> BasicAliasAnalysis.cpp seems more than intelligent enough to detect
>> both of these cases as not aliasing.
>>
>> More to the point, the X86 assembly I get from compiling this is:
>>
>> opt -O3 test_alias.ll | llc -filetype=asm
>> ...
>> _A: ## @A
>> movss (%rdi), %xmm0
>> movss %xmm0, 4096(%rdi)
>> movss (%rdi), %xmm0
>> ret
>>
>> ...
>> _B: ## @B
>> movss (%rdi), %xmm0
>> movss %xmm0, (%rsi)
>> ret
>> ...
>>
>> Note the redundant movss in A.
>>
>> Any idea what I'm doing wrong?
>
> Are you providing target data? AA skips a bunch of calculations when
> the the size of a pointer isn't specified.
>
> -Eli
>
Thanks, that was it.
- Andrew
More information about the llvm-dev
mailing list