[LLVMdev] Phi + Select Optimization
Roland Leißa
leissa at cs.uni-saarland.de
Thu May 17 19:30:00 PDT 2012
Oh forgot to mention:
This patch is just a small proof of concept.
Actually, the idea should also work when there is a whole chain of selects like this:
a = phi(X, X, undef, undef, X, undef)
b = select cond1, ..., a
c = select cond2, ..., b
X = select cond3, ..., c
Note the operand order in the select is not important.
--
Roland
----- Original Message -----
> From: "Roland Leißa" <leissa at cs.uni-saarland.de>
> To: llvmdev at cs.uiuc.edu
> Sent: Donnerstag, 17. Mai 2012 19:15:22
> Subject: [LLVMdev] Phi + Select Optimization
>
> 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
> _______________________________________________
> 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