[LLVMdev] Aliasing confusion

andrew adams andrew.b.adams at gmail.com
Fri Oct 7 14:15:02 PDT 2011


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?

I am using what I believe is the most recent svn version (llvm version
3.0svn, revision 141415).

- Andrew




More information about the llvm-dev mailing list