[LLVMdev] Phi + Select Optimization

Duncan Sands baldrick at free.fr
Sun May 20 09:43:40 PDT 2012


Hi Roland,

> If we have this:
>
> a = phi(X, X, undef, undef, X, undef)

such a phi should already be replaced by X if X dominates this basic block.
Is this not the case?  Or does each X here not necessary represent the same
value?

Ciao, Duncan.

> X = select cond, sth, a
>
> or this:
>
> a = phi(X, X, undef, undef, X, undef)
> X = select cond, a, sth
>
> we can replace the phi by 'a' and the select by 'sth'.
>
> Why does this work?
>
> Well, in those cases where control-flow happens to hit the phi from undef edges the select can just "wish" to get 'sth' instead of 'a'.
> In the other case, the phi depends on itself.
> Thus, we can remove it.
>
> The attached patch implements that.
> This is really useful in vectorized code, when there are a lot of selects in order to implement "vectorized control-flow".
>
> Also, there is a minor enhancement which improves SimplifySelectInst to also simplify when the condition is a vector of all true or false values.
>
> Enjoy,
> Roland
>
>
>
> _______________________________________________
> 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