[llvm-bugs] [Bug 31994] New: std::to_string with constant input not optimized to string constant

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Feb 17 07:47:40 PST 2017


            Bug ID: 31994
           Summary: std::to_string with constant input not optimized to
                    string constant
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: trass3r at gmail.com
                CC: llvm-bugs at lists.llvm.org

#include <string>
std::string foo() {
    return std::to_string(5u);

$ clang++ -S -O3 -std=c++14
foo[abi:cxx11]():                         # @foo[abi:cxx11]()
        push    rbx
        mov     rbx, rdi
        mov     esi, vsnprintf
        mov     edx, 16
        mov     ecx, .L.str
        mov     r8d, 5
        xor     eax, eax
        call    __gnu_cxx::__to_xstring(int (*)(char*, unsigned long, char
const*, __va_list_tag*), unsigned long, char const*, ...)
        mov     rax, rbx
        pop     rbx

There was a post on the libstdc++ mailing list about this some time ago. They
recommended better optimization of the vsnprintf builtin:

When using the specialized to_string implementation from VisualC's STL gcc and
clang are perfectly able to figure out the string constant.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170217/4eb2966a/attachment.html>

More information about the llvm-bugs mailing list