Landing: b3ade4e315e5

Project / Subsystem

gcc / match.pd

Date

2026-06-12

Author

Kael Andrew Alonzo Franco

Commit

b3ade4e315e5bab56eced1e22eceabbf1a8f15c4

Source

github

Perf win

Yes

Breaking

No

All attributes

project
gcc
subsystem
match.pd
patch_id
commit_hash
b3ade4e315e5bab56eced1e22eceabbf1a8f15c4
source_type
github
headline
Optimize bitwise operations for signed integers to -1
tldr
GCC now simplifies `(~a) >> a` to `-1` for signed integer `a`, reducing unnecessary computations during compilation.
author
Kael Andrew Alonzo Franco
outcome
committed
performance_win
true
breaking_change
false
series_id
series_parts
[]
tags
  • optimization
  • bitwise
  • tree-ssa
discussion_id_link
bugzilla_pr
date
2026-06-12T00:00:00.000Z

This commit introduces an optimization in match.pd where the expression (~a) >> a simplifies to -1 when a is a signed integer. This transformation is based on the mathematical equivalence ~(a>>a) for right shifts of complement operations. By recognizing this pattern and directly substituting -1, the compiler eliminates redundant bitwise operations, resulting in more efficient code generation.