https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112545
--- Comment #5 from Jeffrey A. Law <law at gcc dot gnu.org> --- So I've been pondering this a bit and I think there's a reasonable path forward here. Given something like A eq/ne (A relop C) we ought to be able to cobble together a match.pd pattern which tests the possibilities and simplifies the code. If we think about the EQ case. We just need to test 0 EQ (0 relop C) and 1 EQ (1 relop C). If both are false, then the entire condition is false. If only one of them is true, then we can simplify to A == 0 or A == 1 depending on which was true. If both are true, then it simplifies to (unsigned) A <= 1. We can construct something roughtly similar for NE.