If we have two comparisons:
%iszero = icmp eq i32 %A, 0 %isnotzero = icmp ne i32 %A, 0
we should be able to turn one into the logical not of the other:
%iszero = icmp eq i32 %A, 0 %isnotzero = xor i1 %iszero, true
This fixes PR27431.
As a canonicalization, this makes sense, but I'm worried it will lead to bad code generation. Having to materialize a flag into a register to negate it seems potentially problematic. Do we already have code in the backend (CGP?) which undoes this transformation? If not, I think we're likely to need it.
Also, how does this impact the dominating condition optimizations in SimplifyCFG and JumpThreading? Those optimizations expect the dominated conditional branch to be fed by a compare rather than a not of the dominating compare.
My suggestion, given the comments on this thread, would be for someone to
make a decision (or build a consensus) on what the canonical form of this
kind of thing should look like, and then we just go and make everything do
that :P, whether it's the result david has produced, or compare over
compare, or whatever.