This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Optimize lshr+shl+and conversion pattern
ClosedPublic

Authored by bcl5980 on Jun 9 2022, 8:09 PM.

Details

Summary

if C1 and C3 are pow2 and Log2(C3) >= C2:

((C1 >> X) << C2) & C3 -> X == (Log2(C1)+C2-Log2(C3)) ? C3 : 0

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

Diff Detail

Event Timeline

bcl5980 created this revision.Jun 9 2022, 8:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 8:09 PM
bcl5980 requested review of this revision.Jun 9 2022, 8:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 8:09 PM
bcl5980 updated this revision to Diff 435778.Jun 9 2022, 8:12 PM

update test

bcl5980 updated this revision to Diff 435783.Jun 9 2022, 8:40 PM
bcl5980 edited the summary of this revision. (Show Details)

C3 support non-uniform constant for shl+lshr and lshr+shl
update tests.

bcl5980 updated this revision to Diff 435791.Jun 9 2022, 8:58 PM

add nullptr check

I don't like increasing risk by combining what are really 2 independent changes into 1 patch.
Please go back to the earlier revision that only adds the new fold. We can ease the vector restrictions as a second step (I haven't seen any evidence that those cases matter, but it opens up more possibilities to miscompile in ways that are very hard to detect).

bcl5980 updated this revision to Diff 436141.Jun 11 2022, 7:10 AM

revert to diff2

bcl5980 edited the summary of this revision. (Show Details)Jun 11 2022, 7:11 AM
spatel accepted this revision.Jun 13 2022, 7:23 AM

LGTM

This revision is now accepted and ready to land.Jun 13 2022, 7:23 AM
This revision was landed with ongoing or failed builds.Jun 13 2022, 8:06 PM
This revision was automatically updated to reflect the committed changes.