[LLVMdev] Functions: sret and readnone

Chris Lattner clattner at apple.com
Mon Oct 5 09:56:03 PDT 2009


On Oct 5, 2009, at 7:21 AM, Stephan Reiter wrote:

> Hi all,
>
> I'm currently building a DSL for a computer graphics project that is
> not unlike NVIDIA's Cg. I have an intrinsic with the following
> signature
>
> float4 sample(texture tex, float2 coords);
>
> that is translated to this LLVM IR code:
>
> declare void @"sample"(%float4* noalias nocapture sret, %texture,
> $float2) nounwind readnone

The best thing to do to handle this is to add a custom AliasAnalysis  
implementation, which will know the precise mod/ref sets for the  
function.  See docs/AliasAnalysis.html for some more information.

-Chris

>
> The type float4 is basically an array of four floats, which cannot be
> returned directly on an x86 using the traditional calling conventions
> but only via the sret mechanism.
>
> You might already have spotted that "readnone" attribute, which is
> causing some problems: The GVN optimization pass seems to treat the
> sret pointer just like any other pointer to memory and eliminates all
> calls to the function, since it sees it as returning void without
> touching any memory. Is there a way to make sure that the GVN pass
> interpretes the sret argument as the actual return value of the
> function? Or are there other approaches I could try?
>
> Currently, the only way to make sure that the sample function behaves
> as expected is to drop the "readnone" attribute, but that obviously
> hinders optimization ...
>
> Thanks a lot,
> Stephan
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list