[LLVMdev] Functions: sret and readnone
Stephan Reiter
stephan.reiter at gmail.com
Mon Oct 5 07:21:23 PDT 2009
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 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
More information about the llvm-dev
mailing list