https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121006
Bug ID: 121006 Summary: if (float_var == CST || float_var== -CST) is known to be true, __builtin_copysignf(CST, float_var) can be optimized to just float_var Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` float f1(float a) { if (a == 1.0 || a == -1.0) return __builtin_copysignf(1.0, a); return a; } float f0(float a) { if (a == 0.0 || a == -0.0) return __builtin_copysignf(0.0, a); return a; } float fpi(float a) { float x = 3.141592; if (a == x || a == -x) return __builtin_copysignf(x, a); return a; } ``` These all should be optimized to just `return a`. LLVM is able to do each one except for f0 (but I think that is because it is pattern matching here). With frange we have for fpi: ``` a_4(D) [frange] float [-3.1415920257568359375e+0 (-0x0.c90fd8p+2), 3.1415920257568359375e+0 (0x0.c90fd8p+2)] <bb 4> : _6 = __builtin_copysignf (3.1415920257568359375e+0, a_4(D)); // predicted unlikely by early return (on trees) predictor. ```