https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67287
Bug ID: 67287 Summary: FRE should CSE sqrt() calls even with -ferrno-math Product: gcc Version: 6.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- double sqrt(double x); double t (double x) { double a = sqrt (x); double b = sqrt (x); return a * b; } should be optimized to double t (double x) { double a = sqrt (x); return a * a; } with -fmath-errno. FRE currently gives up too early and the alias oracle can handle errno-style references (but it can't use a call as a "ref", so the "errno"-only side-effect has to be modeled by creating a special ref for performing the walking for math builtins setting errno as their only side-effect). We may not miscompile sqrt (x); errno = 0; sqrt (x); if (errno != 0) ... to CSE the second sqrt.