Landing: b59ff31043ae

Project / Subsystem

gcc / gcc/match.pd

Date

2026-08-07

Author

Kyrylo Tkachov

Commit

b59ff31043ae6b1a5ce8582dd375e2ef9a938d79

Source

github

Perf win

Yes

Breaking

No

All attributes

project
gcc
subsystem
gcc/match.pd
patch_id
—
commit_hash
b59ff31043ae6b1a5ce8582dd375e2ef9a938d79
source_type
github
headline
Fold overflow-free average idiom to fewer operations
tldr
GCC now simplifies a common overflow-safe integer average calculation into a more efficient form.
author
Kyrylo Tkachov
outcome
committed
performance_win
true
breaking_change
false
series_id
—
series_parts
[]
tags
  • • optimization
  • • integer
  • • aarch64
discussion_id_link
—
bugzilla_pr
—
date
2026-08-07T00:00:00.000Z

GCC’s pattern matching system (match.pd) has gained a new rule to simplify a common, overflow-free way of calculating the average of two integers. The idiom ((x >> 1) + (y >> 1)) + (x & y & 1) is now transformed into the mathematically equivalent but more efficient (x & y) + ((x ^ y) >> 1). This optimization reduces the number of operations, leading to performance improvements on various architectures, including aarch64, and is also beneficial for vectorization.