[LLVMdev] Functions: sret and readnone

Duncan Sands baldrick at free.fr
Fri Nov 6 03:12:49 PST 2009


Hi Stephan,

> intrinsic float4 sample(int tex, float2 tc);
> 
> float4 main(int tex, float2 tc)
> {
> 	float4 x = sample(tex, tc);
> 	return 0.0;
> }

without additional information it would be wrong to remove the call to
sample because it might write to a global variable.

> As you can see, the call to the sample function is still present,
> although the actual value it is supposed to return via its sret
> parameter is never used.

Quite right too, see above.

> Using the AAEvalPass I found out that the alias analysis pass I
> implemented seems to work alright (it reports mod for %5):
> 
> ===== Alias Analysis Evaluator Report =====
>   3 Total Alias Queries Performed
>   3 no alias responses (100.0%)
>   0 may alias responses (0.0%)
>   0 must alias responses (0.0%)
>   Alias Analysis Evaluator Pointer Alias Summary: 100%/0%/0%
>   3 Total ModRef Queries Performed
>   2 no mod/ref responses (66.6%)
>   1 mod responses (33.3%)
>   0 ref responses (0.0%)
>   0 mod & ref responses (0.0%)
>   Alias Analysis Evaluator Mod/Ref Summary: 66%/33%/0%/0%
> 
> Yet, DCE, DSE and GVN fail to remove the function call. (I'm not so
> sure which optimization pass to use, so I picked these three as they
> seemed to make sense.)

In order to perform this transform the optimizers would have to work out
that sample does not modify any global state.  This cannot be done without
knowing the definition of sample, but you only provide a declaration.  If
you provided a body too then the GlobalsModRef analysis might be able to
work it out.

Ciao,

Duncan.



More information about the llvm-dev mailing list