[LLVMdev] Phi + Select Optimization

Roland Leißa leissa at cs.uni-saarland.de
Thu May 17 19:15:22 PDT 2012


Hi all,

I've just written a small enhancement to SimplifyPHINode.

The idea is the following:

If we have this:

a = phi(X, X, undef, undef, X, undef)
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: phi_select_opt.diff
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120518/6cecec0f/attachment.bin>


More information about the llvm-dev mailing list