https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112982
Bug ID: 112982 Summary: Missing optimization: fold max(b, a + 1) to b when a < b Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xxs_chy at outlook dot com Target Milestone: --- Godbolt example: https://godbolt.org/z/nn8hT16Ka long src(long a, long b) { if(a < b){ return max(b, a + 1); }else{ return 0; } } can be folded to: long tgt(long a, long b) { if(a < b){ return b; }else{ return 0; } } Similarly, such pattern can be generalized to `a > b`, `min(b, a + 1)`. Both GCC and LLVM missed such optimization opportunity.