This is an archive of the discontinued LLVM Phabricator instance.

Added InstCombine Transformation for (A^B)^((~A)&B) -> A&(~B)
Needs ReviewPublic

Authored by ankur29.garg on Aug 21 2014, 2:33 AM.

Details

Summary

Hi everyone,

This patch implements the transformation (A^B)^((~A)&B) -> A&(~B)

Please help in reviewing it.

Z3 Link: http://rise4fun.com/Z3/jegC

Thanks,
Ankur Garg

Diff Detail

Event Timeline

ankur29.garg retitled this revision from to Added InstCombine Transformation for (A^B)^((~A)&B) -> A&(~B).
ankur29.garg updated this object.
ankur29.garg edited the test plan for this revision. (Show Details)
ankur29.garg set the repository for this revision to rL LLVM.
ankur29.garg added a subscriber: Unknown Object (MLST).
majnemer edited edge metadata.Aug 22 2014, 10:59 AM

This can be generalized.

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

ankur29.garg edited edge metadata.

Hi David,
Thank you for the comments.
I have made the changes as you suggested. Please review the updated revision.

Updated Transformation:
(A ^ B) ^ ((A ^ C) & B) -> (C ^ (B | (A ^ C))

New Z3 Link: http://rise4fun.com/Z3/KmnV7

Thanks,
Ankur Garg

asl added a subscriber: asl.Aug 23 2014, 11:08 AM

Again, it will be really nice if you'll provide examples in the
real-world programs which would require and benefit such matching
patterns.

Hi Anton,
Thank You for reviewing the patch.
The simplified expression reduces the number of operations required for the calculation of the original expression from 4 to 3. Just like most of the other transformations, it will reduce the computation. I am not exactly sure what you meant by real world examples. Can you please clarify ?

Thanks.
Regards,
Ankur Garg

asl added a comment.Aug 28 2014, 4:55 AM

There are infinitely many expressions which one can form using logical
operations. And for given expression there surely is the minimal form
which one can use to compute.The question is how often such
transformation occur so it's profitable to explicitly match in
optimizer.

Will you please provide some numbers, for example how often such
pattern occurs in LLVM testsuite and in SPEC?

Hi Anton,
I understood what you are asking. I was also thinking the same thing when I was browsing through other patches. I do think there should be a general method to include simplification of all such logical expressions' simplifications. While I was going through other patches, I came across this, http://reviews.llvm.org/D4940 . Also, I was curious as to how gcc includes such expression simplifications.

Regards,
Ankur Garg

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 11:05 AM
dexonsmith resigned from this revision.Sep 2 2019, 3:52 PM