This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by xbolva00 on Sep 4 2019, 5:23 AM.

Details

Summary
Name: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
%or = or i32 %y, %x
%and = and i32 %x, %y
%sub = sub i32 %and, %or
  =>
%sub1 = xor i32 %x, %y
%sub = sub i32 0, %sub1

Optimization: sub(and(x, y), or(x, y)) -> neg(xor(x, y))
Done: 1
Optimization is correct!

https://rise4fun.com/Alive/VI6

Found by @lebedev.ri. Also author of the proof.

Diff Detail

Repository
rL LLVM

Event Timeline

xbolva00 created this revision.Sep 4 2019, 5:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 4 2019, 5:23 AM
lebedev.ri requested changes to this revision.Sep 4 2019, 5:28 AM
lebedev.ri added inline comments.
lib/Transforms/InstCombine/InstCombineAddSub.cpp
1731–1732 ↗(On Diff #218655)

&& (Op0.hasOneUse() || Op1.hasOneUse())

1733 ↗(On Diff #218655)

Not != Neg

This revision now requires changes to proceed.Sep 4 2019, 5:28 AM
xbolva00 updated this revision to Diff 218660.Sep 4 2019, 5:45 AM
xbolva00 retitled this revision from [InstCombine] Fold sub (and A, B) (or A, B)) to not (xor A, B) to [InstCombine] Fold sub (and A, B) (or A, B)) to neg (xor A, B).

Addressed review notes

xbolva00 marked 3 inline comments as done.Sep 4 2019, 5:45 AM
xbolva00 added inline comments.
lib/Transforms/InstCombine/InstCombineAddSub.cpp
1733 ↗(On Diff #218655)

Oops..

lebedev.ri accepted this revision.Sep 4 2019, 7:33 AM
lebedev.ri added a reviewer: spatel.

LG

This revision is now accepted and ready to land.Sep 4 2019, 7:33 AM
This revision was automatically updated to reflect the committed changes.
xbolva00 marked an inline comment as done.