https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68294
Bug ID: 68294 Summary: gcc cannot deduce (a | b) != 0 from (a != 0 && b != 0) Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fuz at fuz dot su Target Milestone: --- I implemented Stein's binary gcd algorithm, which contains code like this: int u, v, k; /* ... */ if (u == 0 || v == 0) return (u | v); k = ffs(u | v) - 1; Sadly, for the ffs() call, gcc emits (on x86 where behaviour of bsf is unclear if the operand is zero) code for the case when u | v is zero, even though this possibility has been ruled out in the if-statement before. Adding a redundant clause if ((u | v) == 0 || u == 0 || v == 0) to the if-statement makes the compiler omit the extra code it emits above, but then it emits an extra unneeded test for (u | v) == 0. It would be great if gcc would catch this.