[LLVMdev] Simplifying selects + arm stuff

Chris Lattner sabre at nondot.org
Thu Nov 11 09:09:36 PST 2010


On Nov 11, 2010, at 8:30 AM, Duncan Sands wrote:

> Hi Chris,
> 
>> Instead of turning this into a phase ordering issue, I'd rather increase the power of the folding logic to catch the general form.  In this case, instead of handling this in instsimplify, why not handle this in reassociate?
>> 
>> This is conceptually no different than (x&  y&  x) ->  (x&  y), it's just that in this case you have: (x&  y&  (x or -1)) which should fold to (x&  y) just the same.
> 
> in fact this already works, at least for the given example:
>  -instcombine -reassociate -instcombine results in:
> 
> original:
>   %z = and i32 %x, %y
>   %s = select i1 %cond, i32 %y, i32 %z
>   %r = and i32 %x, %s
> 
> after first instcombine:
>   %z = select i1 %cond, i32 -1, i32 %x
>   %s = and i32 %z, %y
>   %r = and i32 %s, %x
> 
> after reassociate:
>   %z = select i1 %cond, i32 -1, i32 %x
>   %s = and i32 %y, %x
>   %r = and i32 %s, %z
> 
> after second instcombine:
>   %s = and i32 %y, %x
> 
> This might be a coincidence, but I am happy for the moment :)

Ok!  If this "conditional and" idiom is common, it would still be worth teaching reassociate about it, so we don't run into phase order issues.

-Chris



More information about the llvm-dev mailing list