The existing code already considered this case. Unfortunately a typo in the condition prevents it from triggering. Also the existing code, had it run, forgot to do the folding.
This fixes PR42876
That comment makes me nervous given the logic. Can we assert that N has one user and that user is a br?
The code is checking for '1' not '-1'.
There are two callers of this function visitSETCC, which passes a node generated by SimplifySetCC, and visitBRCOND which does indeed check that the passed node has just one use.
I'm less sure about the the node coming out of SimplifySetCC so it might make sense to err on the safe side here?
(*N->use_begin())->getOpcode() == ISD::BRCOND) should go, or make it an assert.
I'm not really sure what's on the other unsafe side, against what is this protecting?