Landing: e0c4c4cb0238

Project / Subsystem

gcc / match

Date

2026-05-02

Author

Avinal Kumar

Commit

e0c4c4cb02382b37a41da098aab3a2446d3cdf3e

Source

github

Perf win

Yes

Breaking

No

All attributes

project
gcc
subsystem
match
patch_id
commit_hash
e0c4c4cb02382b37a41da098aab3a2446d3cdf3e
source_type
github
headline
Optimize ``A > B ? ABS(A) : B`` to ``MAX(A, B)`` When B >= 0
tldr
GCC now optimizes ``A > B ? ABS(A) : B`` to ``MAX(A, B)`` when it knows ``B`` is non-negative, enabling more efficient code generation.
author
Avinal Kumar
outcome
committed
performance_win
true
breaking_change
false
series_id
series_parts
[]
tags
  • optimization
discussion_id_link
bugzilla_pr
date
2026-05-02T00:00:00.000Z

GCC’s pattern matching infrastructure now optimizes expressions of the form A > B ? ABS(A) : B into MAX(A, B) when it knows B is non-negative. This transformation is valid because if B is non-negative and A > B, then A must also be positive, making ABS(A) equivalent to A. This optimization is performed at -O1, where previously it was only done at -O2.