https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109401
Bug ID: 109401 Summary: Optimise max (a, b) + min (a, b) into a + b Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ktkachov at gcc dot gnu.org Target Milestone: --- The testcase #include <algorithm> #include <stdint.h> uint32_t foo (uint32_t a, uint32_t b) { return std::max (a, b) + std::min (a, b); } uint32_t foom (uint32_t a, uint32_t b) { return std::max (a, b) * std::min (a, b); } could optimise foo into a + b and foom into a * b. Should be a matter of some match.pd patterns?