We can do
(ShiftValC >> Y) >s -1 --> Y != 0,
(ShiftValC >> Y) <s 0 --> Y == 0,
with ShiftValC < 0
https://alive2.llvm.org/ce/z/-PRHfD
https://alive2.llvm.org/ce/z/bWfp-s
Differential D129726
[InstCombine] (ShiftValC >> Y) >s -1/<s 0 --> Y != 0/==0 Chenbing.Zheng on Jul 13 2022, 8:37 PM. Authored by
Details We can do https://alive2.llvm.org/ce/z/-PRHfD
Diff Detail
Unit Tests Event TimelineComment Actions This will not solve the problem in general. We need to add a fold for lshr values. We should be able to optimize something like this: Can we generalize or adapt this recent patch? Comment Actions address comment,
Comment Actions LGTM
|
We should also handle the related pattern that is checking if the shifted value is negative:
https://alive2.llvm.org/ce/z/bWfp-s
Using InstCombiner::isSignBitCheck() can reduce the code needed to match these patterns. Look around this file for examples of usage.