Basically porting over the behaviour in AArch64ISelLowering to GISel. See emitComparison for reference.
When we have something like this:
lhs = G_SUB 0, y ... G_ICMP lhs, rhs
We can fold away the G_SUB and produce a cmn instead, given that we produce the same value in NZCV.
Add a test showing that the transformation works, and also showing that we don't perform the transformation when it's unsafe.
This function generates semantically incorrect GMIR and then relies on the caller to fix and select it. I would rather we also modify the opcode in this function to ANDS[WX]rr and then have the caller check the return value to see if it needs to modify the opc. That way, on entry and exit we have semantically correct, if only partially selected, MIR.