[llvm-commits] [Patch] Missed instsimplify transformation

Duncan Sands baldrick at free.fr
Wed Jul 27 00:20:16 PDT 2011


Hi Hans,

> The attached patch adds a simplification for
>
> ((A&  1) == 0) | (A == 0) to
> (A&  1) == 0
>
> Is this ok to add to instsimplify?

this kind of thing and many variations indeed turn up all the time.  It is
a special case of: X | Y simplifies to X if Y implies X (in your case A == 0
implies A & 1 == 0).  I would prefer to add some general machinery for handling
this kind of thing, rather than sticking in a few cases, because there are so
many different forms of this that occur.  What I had in mind was introducing a
Facts class that can store a certain number of facts like "A == 0", and would
be passed internally to instsimplify routines.  When trying to simplify "X | Y"
you would push the fact Y into the Facts object, then try to simplify X.  When
simplifying "(A & 1) == 0", you would recursively try to simplify "A & 1"; when
simplifying "A & 1" the fact "A == 0" would apply, allowing you to replace A
with 0, giving "0 & 1" which would simplify to 0, resulting in "(A & 1) == 0"
simplifying to "true".  This would show that Y => X in your case, so you would
then pop the fact from the Facts object and return X as the simplification for
"X | Y".

Unfortunately I don't have time to work on this right now - would you like to?

Ciao, Duncan.



More information about the llvm-commits mailing list