This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Optimize shift+and+xor conversion pattern to simple comparison
AbandonedPublic

Authored by bcl5980 on Jun 12 2022, 9:50 PM.

Details

Summary

if C1 and C2 are pow2:

((C1 << X) & C2) ^ C2 --> (X != (Log2(C2)-Log2(C1)) ? C2 : 0

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

if C1 and C2 are pow2:

((C1 >> X) & C2) ^ C2 --> (X != (Log2(C1)-Log2(C2)) ? C2 : 0

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

Diff Detail

Event Timeline

bcl5980 created this revision.Jun 12 2022, 9:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2022, 9:50 PM
bcl5980 requested review of this revision.Jun 12 2022, 9:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2022, 9:50 PM
bcl5980 edited the summary of this revision. (Show Details)Jun 12 2022, 9:50 PM
bcl5980 edited the summary of this revision. (Show Details)
bcl5980 edited the summary of this revision. (Show Details)
bcl5980 retitled this revision from [InstCombine] Optimise shift+and+xor conversion pattern to simple comparison to [InstCombine] Optimize shift+and+xor conversion pattern to simple comparison.Jun 12 2022, 9:53 PM
spatel added inline comments.Jun 14 2022, 2:10 PM
llvm/test/Transforms/InstCombine/and.ll
1893

I don't see a good reason to canonicalize this to icmp+select, but leave the previous test as shift+and.

We discussed transforming the simpler pattern starting with mask-by-power-of-2 in an earlier patch. I drafted a patch for that already and didn't notice any regressions. I will clean that up and post it for review.

bcl5980 abandoned this revision.Jun 14 2022, 7:28 PM