Page MenuHomePhabricator

[InstCombine] Fold sub (or A, B) (and A, B) to (xor A, B)
ClosedPublic

Authored by xbolva00 on Wed, Sep 4, 4:18 AM.

Details

Summary
Name: sub or and to xor
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %or, %and
  =>
%sub = xor i32 %x, %y

Optimization: sub or and to xor
Done: 1
Optimization is correct!

https://rise4fun.com/Alive/eJu

Diff Detail

Repository
rL LLVM

Event Timeline

xbolva00 created this revision.Wed, Sep 4, 4:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptWed, Sep 4, 4:18 AM
xbolva00 updated this revision to Diff 218643.Wed, Sep 4, 4:26 AM
xbolva00 retitled this revision from [InstCombine]Fold (sub (or A, B) (and A, B) to (xor A, B) to [InstCombine] Fold sub (or A, B) (and A, B) to (xor A, B).Wed, Sep 4, 4:28 AM
lebedev.ri edited the summary of this revision. (Show Details)Wed, Sep 4, 4:31 AM
lebedev.ri accepted this revision.Wed, Sep 4, 4:37 AM

LG.
There's also sub(and(x, y), or(x, y)) -> neg(xor(x, y))
https://rise4fun.com/Alive/VI6
https://godbolt.org/z/OMu71B

/home/xbolva00/LLVM/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
1724 ↗(On Diff #218643)

extra unneeded braces

test/Transforms/InstCombine/sub-or-and-xor.ll
69–78 ↗(On Diff #218643)

Precommit.

This revision is now accepted and ready to land.Wed, Sep 4, 4:37 AM
xbolva00 updated this revision to Diff 218648.Wed, Sep 4, 4:49 AM

Rebased, fixed braces

Thanks!

There's also sub(and(x, y), or(x, y)) -> neg(xor(x, y))

Ok, I will prepare a patch soon.

xbolva00 updated this revision to Diff 218649.Wed, Sep 4, 4:57 AM
This revision was automatically updated to reflect the committed changes.

And also
sub(xor(x, y), or(x, y)) -> neg(and(x, y))

https://rise4fun.com/Alive/8OI