Landing: c8aaf14bf688

Project / Subsystem

gcc / match.pd

Date

2026-09-29

Author

Dominic P

Commit

c8aaf14bf6882705d2515a5eb9c15de7f4034c5b

Source

github

Perf win

No

Breaking

No

All attributes

project
gcc
subsystem
match.pd
patch_id
—
commit_hash
c8aaf14bf6882705d2515a5eb9c15de7f4034c5b
source_type
github
headline
match.pd: Prevent incorrect folding of minmax(a-c, b) + c
tldr
Fixes an optimization that incorrectly folded arithmetic involving unsigned subtraction that wraps around.
author
Dominic P
outcome
committed
performance_win
false
breaking_change
false
series_id
—
series_parts
[]
tags
  • • optimization
  • • compiler
  • • correctness
discussion_id_link
—
bugzilla_pr
—
date
2026-09-29T00:00:00.000Z

An optimization pass in GCC’s pattern matching (match.pd) incorrectly folded expressions of the form minmax(a - c, b) + c. This fold was valid only if a - c did not wrap around (underflow) for unsigned types. The bug allowed incorrect transformations when a was small and c was large, leading to different results for the original and optimized expressions. This change adds a check using range_op_handler to ensure a - c is overflow-free before applying the fold, thus correcting the optimization.