This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by xbolva00 on Sep 4 2019, 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

Event Timeline

xbolva00 created this revision.Sep 4 2019, 4:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 4 2019, 4:18 AM
xbolva00 updated this revision to Diff 218643.Sep 4 2019, 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).Sep 4 2019, 4:28 AM
lebedev.ri edited the summary of this revision. (Show Details)Sep 4 2019, 4:31 AM
lebedev.ri accepted this revision.Sep 4 2019, 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

Precommit.

This revision is now accepted and ready to land.Sep 4 2019, 4:37 AM
xbolva00 updated this revision to Diff 218648.Sep 4 2019, 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.Sep 4 2019, 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