This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold ((A&B)^A)|((A&B)^B) to A^B
ClosedPublic

Authored by marcauberer on Sep 1 2023, 1:19 PM.

Details

Summary

Depends on D159379

((A & B) ^ A) | ((A & B) ^ B) -> A ^ B
(A ^ (A & B)) | (B ^ (A & B)) -> A ^ B
((A & B) ^ B) | ((A & B) ^ A) -> A ^ B
(B ^ (A & B)) | (A ^ (A & B)) -> A ^ B

Alive2: https://alive2.llvm.org/ce/z/i44xmq
Baseline tests: https://reviews.llvm.org/D159379

Diff Detail

Event Timeline

marcauberer created this revision.Sep 1 2023, 1:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 1:19 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
marcauberer requested review of this revision.Sep 1 2023, 1:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 1:19 PM
goldstein.w.n added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3669
  1. the m_Xor -> m_c_Xor
  2. Put this in a lambda so you don't need to duplicate the match logic and just do SomeFuncName(Op0, Op1) / SomeFuncName(Op1, Op0).
marcauberer edited the summary of this revision. (Show Details)Sep 1 2023, 2:18 PM

Use lambda to avoid code duplication

marcauberer marked an inline comment as done.Sep 1 2023, 2:20 PM

Reflect changes to tests

huihuiz added inline comments.Sep 7 2023, 1:41 PM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3668

Remove "; Result != nullptr". Not needed.

3670

Same.

marcauberer marked 2 inline comments as done.

Remove unnecessary nullptr checks

huihuiz accepted this revision.Sep 7 2023, 1:49 PM
This revision is now accepted and ready to land.Sep 7 2023, 1:49 PM

Can someone land the baseline tests patch and this patch for me? I do not have commit access.

I can help land this patch and the baseline test.
Just give it more hours in case other people catch anything different.

This revision was automatically updated to reflect the committed changes.
nikic added a subscriber: nikic.Sep 14 2023, 6:14 AM
nikic added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3662

Why does this transform have a one-use limitation?