The code here can be extended. I post this patch right now, to get some feedback before adding those extensions.
When we see a SETCC whose only users are zero extend operations, we can replace it with a subtraction. This results in doing all calculation in GPRs and avoids CR use.
Extensions that I plan to look into:
1- Check if this works for any_extend/sign extend
2- Implement similar change for signed condition codes.
3- Look into handling equal and not equal cases, using cntlz
4- More tests should be added
Please let me know if there are other ways for extending this.
Can you please convert to doxygen-style comments?