This folds a negation through a csel, which can come up during the lowering of negative abs.
Looks like a useful optimisation @dmgreen! I left a few minor comments ...
Is it worth having a simple helper function like isNegate for all these cases. Perhaps one already exists?
Does this work when both inputs are negated and do we have a test for that?
I understand you're reusing the opcode and operands here, but it took me a while to realise that! Is it worth just writing out what we're doing here fully for clarity, i.e. something a bit like
SDValue Zero = N->getOperand(0); SDValue N0N = DAG.getNode(ISD::SUB, DL, VT, Zero, N0); SDValue N1N = DAG.getNode(ISD::SUB, DL, VT, Zero, N1);