On 7/10/2026 6:22 AM, Ashley Chekhova wrote:
Changes in v2:
- Type conversion after dereferencing is now always required.
- Fixed the issue regarding strlen being called on pointer-types
other than char *.
- Added a test-case for that issue.
Can you tell why it's restricted to the last full fold?
Restriction to the last full fold comes at the recommendation of Drea
Pinski in comment 6 on the PR
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92408#c6). Perhaps this
doesn't warrant inclusion in the test case? I'm impartial regardless.
---
Checks for strlen(s) == 0 could be rewritten as *s == 0 in the simple
case, but in complex cases (such as those involving variable
assignment), the optimization wouldn't be implemented. Fix this
by moving it over to forwprop from fold-const. Although, since
this currently only runs when PROP_last_full_fold is set, the
original code is kept in as well.
Bootstrapped and tested on x86_64-pc-linux-gnu
PR tree-optimization/92408
gcc/ChangeLog:
* tree-ssa-forwprop.cc (optimize_strlen_comp): Rewrite
strlen(s) == 0 as *s == 0 and strlen(s) != 0 as *s != 0.
* tree-ssa-forwprop.cc (simplify_builtin_call): Added call to
optimize_strlen_comp.
gcc/testsuite/ChangeLog:
+ gcc.dg/pr92408.c: New test.
Signed-off-by: Ashley Chekhova <[email protected]>
Thanks. I fixed some minor whitespace issues in the patch as well as
minor ChangeLog nits and pushed this to the trunk.
jeff