[llvm-commits] PATCH: Allow LICM to sink or lift loads from constant memory

Chris Lattner clattner at apple.com
Tue Jul 22 22:07:19 PDT 2008


On Jul 22, 2008, at 7:00 PM, Stefanus Du Toit wrote:

> Allow LICM to sink or lift loads from constant memory. Also add a test
> case for this.
>
> This allows instructions like loads from global variables declared to
> be constant to be moved out of loops.
>
Hi Stephanus,

<appologizes for the stream of consciousness email>

I don't think this is the right approach.  A better approach would be  
to modify the basicaa pass to say that nothing mod's a pointer that  
points into constant memory.  It already has some of the logic for  
this, but it must be missing a case.

To find out what is happening, use something like:

$ llvm-as < t.ll | opt -count-aa -licm -count-aa-print-all-queries |  
llvm-dis
May alias:	[8B] float** @a, [4B] float* %arrayidx
May alias:	[8B] float** @a, [4B] float* %arrayidx
..
forcond:		; preds = %forbody, %entry
	%i.0 = phi i32 [ 0, %entry ], [ %inc, %forbody ]		; <i32> [#uses=4]
	%cmp = icmp ult i32 %i.0, %count		; <i1> [#uses=1]
	br i1 %cmp, label %forbody, label %afterfor

forbody:		; preds = %forcond
	%tmp3 = load float** @a		; <float*> [#uses=1]
	%arrayidx = getelementptr float* %tmp3, i32 %i.0		; <float*> [#uses=1]
	%tmp7 = uitofp i32 %i.0 to float		; <float> [#uses=1]
	store float %tmp7, float* %arrayidx
	%inc = add i32 %i.0, 1		; <i32> [#uses=1]
	br label %forcond
...


Okay, so this is actually a problem that happens because LICM itself  
is making equivalence sets based on pointers, so these things end up  
in the same set.  This we can see with:

$ llvm-as < t.ll | opt -print-alias-sets
Alias Set Tracker: 1 alias sets for 2 pointer values.
   AliasSet[0xc03a50,2] may alias, Mod/Ref   Pointers: (float** @a,  
8), (float* %arrayidx, 4)

Okay, given that, your patch is fine and I take back what I said  
above.   This is a problem specific to LICM so it is reasonable for  
the fix to be in LICM.  Patch applied:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080721/065322.html

Thanks! :)

-Chris



More information about the llvm-commits mailing list