By moving this transform to InstSimplify from InstCombine, we sidestep the problem/question raised by PR27869:
https://llvm.org/bugs/show_bug.cgi?id=27869
...where InstCombine turns an icmp+zext into a shift causing us to miss the fold.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I think we already do that, but the case in the bug report shows an example where one of the zexts is gone before we reach the and.
I don't believe so, what I imagined was something like the following: https://ghostbin.com/paste/fdc72
Ah - you meant here in InstSimplify; I was still thinking InstCombine. This looks nice. I was wondering how to make the cast without creating an instruction, and your paste answers that: use ConstantExpr::getCast().
Let me add more tests and update. Thanks!
Patch updated:
- Use slightly modified version of David's suggested code to make the transform more general.
- Add tests to cover more possible cases and some negative cases.
- Remove the equivalent transform from InstCombine and move its regression tests to InstSimplify.
This now includes what I thought would be the follow-up step in one patch. I can make step #3 a separate commit if that seems safer. Or if I'm wrong in assuming that everything in the InstCombine path is now handled by InstSimplify, please let me know.