[LLVMdev] Phi + Select Optimization

Roland Leißa leissa at cs.uni-saarland.de
Mon May 21 04:48:35 PDT 2012


Hi Duncan,

thank you for your thoughts.

yes, X represents the same value and yes
a = phi(X, X, undef, undef, X, undef)
gets replaced by X if X dominates the BB.

But:

a = phi(X, X, undef, undef, X, undef)
X = select cond, sth, a

does *not* dominate the BB. The select instruction induces a cycle to the phi 
node: X is defined by the select instruction!

-- 
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
> 
> _______________________________________________
> 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