Landing: b99e67e8ac8e

Project / Subsystem

gcc / match

Date

2026-04-25

Author

Andrew Pinski

Commit

b99e67e8ac8e0333cc74040e9924e88555b7a3e1

Source

github

Perf win

Yes

Breaking

No

All attributes

project
gcc
subsystem
match
patch_id
commit_hash
b99e67e8ac8e0333cc74040e9924e88555b7a3e1
source_type
github
headline
Optimize signed < 0 ? positive : min<signed, positive> to (signed)min<(unsigned), (unsigned)positive>
tldr
GCC now optimizes ternary expressions where a signed value is compared to zero against the minimum of the signed value and a positive one, reducing code size a…
author
Andrew Pinski
outcome
committed
performance_win
true
breaking_change
false
series_id
series_parts
[]
tags
  • optimization
  • ternary
  • pattern matching
  • code generation
discussion_id_link
github:gcc-mirror/gcc#110252
bugzilla_pr
date
2026-04-25T00:00:00.000Z

The compiler can now recognize and optimize a specific pattern in ternary expressions. When code contains the structure signed < 0 ? positive : min<signed, positive>, the compiler transforms it into a sequence using unsigned comparisons and a final cast back to signed. This optimization avoids branches and directly computes the minimum, potentially improving performance, especially in tight loops or frequently executed code paths. The change addresses a missed optimization opportunity initially identified while investigating PR 110252.