Landing: e7b77e39552d
Project / Subsystem
gcc / gcc/tree-optimization
Date
2026-08-14
Author
Daniel Barboza
Commit
e7b77e39552d82141f71f039f70885754de72093
Source
github
Perf win
Yes
Breaking
No
All attributes
- project
- gcc
- subsystem
- gcc/tree-optimization
- patch_id
- —
- commit_hash
- e7b77e39552d82141f71f039f70885754de72093
- source_type
- github
- headline
- Enable constant folding for `strnlen` calls with constant length.
- tldr
- Compiler now folds `__builtin_strnlen` into constants when the length argument is known, improving optimization.
- author
- Daniel Barboza
- outcome
- committed
- performance_win
- true
- breaking_change
- false
- series_id
- —
- series_parts
- []
- tags
-
- • optimization
- • constant folding
- • builtin
- discussion_id_link
- —
- bugzilla_pr
- —
- date
- 2026-08-14T00:00:00.000Z
This commit enhances the fold_const_call.cc pass to recognize and constant-fold calls to __builtin_strnlen when the maximum length argument is a compile-time constant. Previously, only __builtin_strlen was optimized this way. This change allows for better constant propagation and dead code elimination in cases involving bounded string length checks, as demonstrated by an example where a strnlen call with a PHI node input is successfully reduced.