https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95929
Bug ID: 95929 Summary: Failure to optimize tautological comparisons of comparisons to a single one Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- int f(int a, int b) { return (((b != 0) & (a == 0)) | ((a != 0) & (b == 0))); } This can be optimized to `(a != 0) ^ (b != 0)`. I originally found this while compiling this code : inline bool nand(bool a, bool b) { return !(a && b); } int f(int a, int b) { return nand(nand(b, nand(a, a)), nand(a, nand(b, b))); } Which GCC compiles to the above example, and that LLVM optimizes with the transformation I gave (strangely, LLVM does not seem to optimize the example at the top of this bug report to the transformed version if directly given the top example, which is why I'm giving these details as I'm thinking there could be some kind of UB weirdness or something like that with the transformations here)