On 9/15/26 2:06 PM, Andrea Pinski wrote:
This adds a simplification for `x+umax(x,1)` to `umax(x*2, 1)` when `x*2`
is known not to overflow. This shows up with std::vector::push_back
after the patch which adds `x+minmax(a,b)` simplification; it is also
a special case of that patch for `umax and 1`.  This gives a small
code generation improvement with std::vector::push_back because we
trade an add after the umax with a shift beforehand.

Bootstrapped and tested on x86_64-linux-gnu.

Changes since v1:
* v2: rebase

        PR tree-optimization/127103

gcc/ChangeLog:

        * match.pd (`x+umax(x,1)`): New pattern.

gcc/testsuite/ChangeLog:

        * gcc.dg/tree-ssa/max1-plus-1.c: New test.

Signed-off-by: Andrea Pinski <[email protected]>
This series is OK.  While this looks more like canonicalization or otherwise changing the IL to make other optimizations easier without reducing the expression evaluation count, I can't make a case that either form is inherently better than the other.  So given this allows you to zap infeasible paths in patch#2 of the series, it seems like a pragmatic choice.

Jeff

Reply via email to