This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold opposite shifts around an add
AbandonedPublic

Authored by erikdesjardins on Jan 1 2022, 2:11 PM.

Details

Reviewers
None
Summary

((X << C) + Y) >>u C --> (X + (Y >>u C)) & (-1 >>u C)

https://alive2.llvm.org/ce/z/DY9DPg

This replaces a shift with an 'and', and in the case
where the add has a constant operand, it eliminates
both shifts.

As noted in the TODO comment, we already have this fold when
the shifts are in the opposite order (and that code handles
bitwise logic ops too).

Fixes #52851

Diff Detail

Unit TestsFailed

Event Timeline

erikdesjardins created this revision.Jan 1 2022, 2:11 PM
erikdesjardins requested review of this revision.Jan 1 2022, 2:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2022, 2:11 PM
erikdesjardins abandoned this revision.Jan 1 2022, 2:12 PM