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
Paths
| Differential D129726
[InstCombine] (ShiftValC >> Y) >s -1/<s 0 --> Y != 0/==0 ClosedPublic Authored by Chenbing.Zheng on Jul 13 2022, 8:37 PM.
Details Summary We can do https://alive2.llvm.org/ce/z/-PRHfD
Diff Detail
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? Chenbing.Zheng retitled this revision from [InstCombine] add a constraint for x <u minSigned --> x >s -1 to [InstCombine] (ShiftValC >> Y) >s -1 --> Y != 0 with ShiftValC < 0. Comment Actionsaddress comment,
Chenbing.Zheng retitled this revision from [InstCombine] (ShiftValC >> Y) >s -1 --> Y != 0 with ShiftValC < 0 to [InstCombine] (ShiftValC >> Y) >s -1/<s 0 --> Y != 0/==0 . Comment Actionsaddress comments Comment Actions LGTM
This revision is now accepted and ready to land.Jul 20 2022, 6:26 AM This revision was landed with ongoing or failed builds.Jul 20 2022, 7:16 PM Closed by commit rG8c124c908857: [InstCombine] (ShiftValC >> Y) >s -1/<s 0 --> Y != 0/==0 (authored by Chenbing.Zheng). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 446333 llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-shr.ll
|
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.