llvm / llvm/llvm-project

Poor codegen for baseline x86_64 std::to_chars(base=2)

Open
#210,702 0 comments 0 reactions 0 assignees View on GitHub
clang llvm missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

As of @philnik777's #210659, libc++ vectorizes std::to_chars(base=2) (and 16).

However, codegen is quite poor on baseline x86_64 (without avx512), emitting 38 instructions. I can do it in 23. https://godbolt.org/z/na33fhdzz

(For avx512, Clang emits 14 instructions, but I can do 12 https://godbolt.org/z/qjzcnW8q9)

Somewhat discussed on ms-stl discord https://discord.com/channels/737189251069771789/922607955621318697/1528730955823710419

Contributor guide

Open the contributing guide

Research direction

Start with the std::to_chars(base=2) codegen shown in the linked Godbolt examples, comparing baseline x86_64 without AVX-512 against the AVX-512 result. Identify where the emitted instruction counts differ from the examples, then verify that the baseline and AVX-512 codegen improve without regressing the existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.