https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113071
Bug ID: 113071 Summary: `((a == c) || (a == b)) ? a : b` is sometimes not optimized to `(a == c) ? c : b` Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int f(int a, int b, int c) { return ((a == c) | (a == b)) ? a : b; } int f_(int a, int b, int c) { return ((a == b) | (a == c)) ? a : b; } int f1(int a, int b, int c) { return ((a == c) || (a == b)) ? a : b; } int f1_(int a, int b, int c) { return ((a == b) || (a == c)) ? a : b; } int f2(int a, int b, int c) { if (a == c) return a; if (a == b) return a; return b; } int f2_(int a, int b, int c) { if (a == b) return a; if (a == c) return a; return b; } int f3(int a, int b, int c) { if (a == c) return c; return b; } ``` These all should be optimized to the same as f3 but currently only f2 is on all targets while f1 is on targets were logical-op-non-short-circuit is 0. f_, f1_, f2_ all are not optimized either.