[llvm-commits] [llvm] r118378 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp lib/Target/README.txt test/Transforms/InstCombine/select.ll

Duncan Sands baldrick at free.fr
Mon Nov 8 07:19:29 PST 2010


Hi Frits,

> On Mon, Nov 8, 2010 at 2:38 PM, Duncan Sands<baldrick at free.fr>  wrote:
>> Another thing to consider is doing this "looking through select/phi"
>> optimization for other instructions, and not just compares.  For
>> example for logical operations like "and".  What do you think?
>
> I'm pretty sure -instcombine already does things like this, at least
> for bitwise operations like 'and' when combined with 'select' and many
> other instructions (though it doesn't seem to handle 'phi'
> instrutions).

judging from FoldOpIntoSelect, instruction combine transforms
   select(cond, X, Y) and Constant
into
   select(cond, X and Constant, Y and Constant)
Note that it will only do this if select has exactly one use, and it only does
it with a constant, which is pretty restrictive.  The suggested transform would
transform
   select(cond, X, Y) and Z
into
   X and Z
if it can prove that "X and Z" equals "Y and Z".  I think this is always a win
if it can be done, and I don't see any need to restrict to select instructions
with only one use, Z a constant etc.  That said, the way I was thinking of doing
this would result in the transform only being done if both "X and Z" and "Y and
Z" simplify (eg evaluate to constants), as well as being equal.

Ciao,

Duncan.



More information about the llvm-commits mailing list