Landing: afa2c7515d19

Project / Subsystem

gcc / ivopts

Date

2026-09-02

Author

Richard Biener

Commit

afa2c7515d19b01a63bf0bca9a77ea9d55e556a1

Source

github

Perf win

No

Breaking

No

All attributes

project
gcc
subsystem
ivopts
patch_id
—
commit_hash
afa2c7515d19b01a63bf0bca9a77ea9d55e556a1
source_type
github
headline
ivopts: Fix loop bound calculation for eliminated IVs
tldr
Corrects loop bound logic when eliminating induction variables with less-than comparisons to prevent incorrect pointer arithmetic and out-of-bounds access.
author
Richard Biener
outcome
committed
performance_win
false
breaking_change
false
series_id
—
series_parts
[]
tags
  • • optimization
  • • loop
  • • pointer arithmetic
  • • ivopts
discussion_id_link
—
bugzilla_pr
—
date
2026-09-02T00:00:00.000Z

This patch fixes a bug in the induction variable (IV) elimination optimization when the loop exit condition involves a less-than comparison. The previous implementation could unsoundly compute loop bounds, leading to incorrect pointer arithmetic or even out-of-bounds memory access, particularly when loops execute zero times or when offsets are large and wrap around the address space. The fix recomputes the bound more robustly and enforces conditions for safe unsigned comparisons.