Bug 105677 - Calling strlen on a string constant is optimized out, but calling wcslen on a string constant is not
Summary: Calling strlen on a string constant is optimized out, but calling wcslen on a...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.1.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2022-05-20 18:13 UTC by Alex Henrie
Modified: 2024-04-08 21:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-05-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Henrie 2022-05-20 18:13:39 UTC
strlen example, source code:

    #include <string.h>

    int main()
    {
        return strlen("Hello world!");
    }

strlen example, assembly code at -O3:

    movl    $12, %eax
    ret

wcslen example, source code:

    #include <wchar.h>

    int main()
    {
        return wcslen(L"Hello world!");
    }

wcslen example, assembly code at -O3:

    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    leaq    .LC0(%rip), %rdi
    call    wcslen@PLT
    addq    $8, %rsp
    .cfi_def_cfa_offset 8
    ret

Interestingly, Clang produces identical assembly code for both examples, which is what I expected GCC to do.
Comment 1 Andrew Pinski 2022-05-20 18:16:31 UTC
GCC does not optimize any of the wide character functions ...
Comment 2 Richard Biener 2022-05-23 06:49:10 UTC
Thus confirmed.