On 9/19/26 4:29 AM, Samarth Tandale via Sourceware Forge wrote:
From: Samarth Tandale <[email protected]> The pattern: x == C ? y : min (x, y) can be simplified to min (x, y) whenever C >= upper_bound (y), because min (C, y) == y for all values y can take. Similarly: x == C ? y : max (x, y) can be simplified to max (x, y) whenever C <= lower_bound (y). Use ranger to query the value range of y and check the bound condition. PR tree-optimization/125700 gcc/ChangeLog: PR tree-optimization/125700 * match.pd ((x == C) ? y : MIN/MAX (x, y)): New simplification. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr125700.c: New test. * gcc.dg/tree-ssa/pr125700-int-width.c: New test. * gcc.dg/tree-ssa/pr125700-negative.c: New test. * gcc.dg/tree-ssa/pr125700-range.c: New test. Signed-off-by: Samarth Tandale <[email protected]>
Thanks! I've pushed this to the trunk. jeff
