This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by nikic on May 2 2022, 5:33 AM.

Details

Summary

This adds two folds:

The reason why the second fold is necessary is that we consider this to be the canonical form if B is a constant. (I did check whether we can change that, but it looks like a number of folds depend on the current canonicalization, so I ended up adding both patterns here.)

Diff Detail

Event Timeline

nikic created this revision.May 2 2022, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2022, 5:33 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.May 2 2022, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2022, 5:33 AM
nikic edited the summary of this revision. (Show Details)May 2 2022, 7:26 AM
spatel added a comment.May 2 2022, 9:03 AM

Do you see any advantage or disadvantage of treating these as part of haveNoCommonBitsSet()?
https://alive2.llvm.org/ce/z/FNtH4K
We should manage to get the logic reductions already if the 'add' was replaced by 'or'.

nikic updated this revision to Diff 426434.May 2 2022, 9:38 AM

Implement as part of haveNoCommonBitsSet() instead.

The second pattern (canonical form for constants) doesn't get fully folded in this case, so this will require an additional or fold. But that seems like something we'd want to do anyway.

spatel accepted this revision.May 2 2022, 9:46 AM

Implement as part of haveNoCommonBitsSet() instead.

The second pattern (canonical form for constants) doesn't get fully folded in this case, so this will require an additional or fold. But that seems like something we'd want to do anyway.

Thanks - LGTM.

This revision is now accepted and ready to land.May 2 2022, 9:46 AM
This revision was automatically updated to reflect the committed changes.