https://gcc.gnu.org/g:d17572cbff92720d4f38c5b908ada4fdb42c8b1e
commit r17-5562-gd17572cbff92720d4f38c5b908ada4fdb42c8b1e Author: Kevin Stefanov <[email protected]> Date: Tue Sep 29 16:14:57 2026 +0300 RTL: Optimize smax(a, -a) for integer operands to abs(a). This change detects smax(a, -a) and smax(-a, a) at the RTL level for integer operands and optimizes that to abs(a). PR rtl-optimization/126726 gcc/ChangeLog: * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): Detect smax(a, -a) for integers and optimize it to abs(a). Signed-off-by: Kevin Stefanov <[email protected]> Diff: --- gcc/simplify-rtx.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index 6b19008c0d32..1ba99c6bb12e 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -5051,6 +5051,13 @@ simplify_ashift: return op1; if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0)) return op0; + if (INTEGRAL_MODE_P (mode)) + { + if (GET_CODE (op0) == NEG && rtx_equal_p (XEXP (op0, 0), op1)) + return simplify_gen_unary (ABS, mode, op1, mode); + else if (GET_CODE (op1) == NEG && rtx_equal_p (XEXP (op1, 0), op0)) + return simplify_gen_unary (ABS, mode, op0, mode); + } tem = simplify_associative_operation (code, mode, op0, op1); if (tem) return tem;
