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
Paths
| Differential D127610
[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
Diff Detail
Unit TestsFailed Event Timelinebcl5980 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
Revision Contents
Diff 436269 llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/and.ll
llvm/test/Transforms/InstCombine/icmp-and-shift.ll
|
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.