https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109843
Bug ID: 109843 Summary: signbit comparisons -> copysign optimization 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: --- float copysign1(float x, float y) { bool t = __builtin_signbit(x) == 0; bool t1 = __builtin_signbit(y) == 0; return (t == t1) ? y : -y; } float copysign2(float x, float y) { bool t = __builtin_signbit(x) != 0; bool t1 = __builtin_signbit(y) != 0; return (t == t1) ? y : -y; } float copysign3(float x, float y) { bool t = __builtin_signbit(x) != 0; bool t1 = __builtin_signbit(y) == 0; return (t != t1) ? y : -y; } float copysign4(float x, float y) { bool t = __builtin_signbit(x) == 0; bool t1 = __builtin_signbit(y) != 0; return (t != t1) ? y : -y; } float copysign5(float x, float y) { return __builtin_copysignf(x, y); } These all should end up being the same code. Hopefully I didn't mess these up.