[llvm-commits] [Patch] Missed instsimplify transformation

Hans Wennborg hwennborg at google.com
Wed Jul 27 07:29:36 PDT 2011


On Wed, Jul 27, 2011 at 8:20 AM, Duncan Sands <baldrick at free.fr> wrote:
> 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?

I can try :)

Thanks,
Hans




More information about the llvm-commits mailing list