[LLVMdev] Functions: sret and readnone
Kenneth Uildriks
kennethuil at gmail.com
Mon Oct 5 07:59:05 PDT 2009
On Mon, Oct 5, 2009 at 9:21 AM, Stephan Reiter <stephan.reiter at gmail.com> 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 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
I believe you are out of luck for the time being.
I plan to change the codegen stage so that it handles large struct
returns; then you could declare your function to return the four
floats directly and mark it readnone. But I don't have a target date
for that change.
More information about the llvm-dev
mailing list