Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC generates suboptimal code #668

Closed
vitaut opened this issue Mar 3, 2018 · 1 comment
Closed

GCC generates suboptimal code #668

vitaut opened this issue Mar 3, 2018 · 1 comment

Comments

@vitaut
Copy link
Contributor

vitaut commented Mar 3, 2018

Compiling

#include <fmt/core.h>

int main() {
  fmt::print("The answer is {}.", 42);
}

with gcc 7.3 (https://godbolt.org/g/UH8T39) gives

.LC0:
  .string "The answer is {}."
main:
  sub rsp, 56
  mov edx, 2
  mov edi, OFFSET FLAT:.LC0
  mov DWORD PTR [rsp+32], 42
  lea rcx, [rsp+32]
  mov esi, 17
  movdqa xmm0, XMMWORD PTR [rsp+32]
  movaps XMMWORD PTR [rsp], xmm0
  mov DWORD PTR [rsp], 42
  movdqa xmm0, XMMWORD PTR [rsp]
  movaps XMMWORD PTR [rsp+32], xmm0
  call fmt::vprint(fmt::basic_string_view<char>, fmt::basic_format_args<fmt::basic_context<std::back_insert_iterator<fmt::internal::basic_buffer<char> >, char> >)
  xor eax, eax
  add rsp, 56
  ret

compared to clang 4.0.1:

main: # @main
  sub rsp, 24
  mov qword ptr [rsp], 42
  mov rcx, rsp
  mov edi, .L.str
  mov esi, 17
  mov edx, 2
  call fmt::vprint(fmt::basic_string_view<char>, fmt::basic_format_args<fmt::basic_context<std::back_insert_iterator<fmt::internal::basic_buffer<char> >, char> >)
  xor eax, eax
  add rsp, 24
  ret

.L.str:
  .asciz "The answer is {}."
@vitaut
Copy link
Contributor Author

vitaut commented Mar 4, 2018

GCC trunk generates the same code as clang: https://godbolt.org/g/NoUbTh, but it's probably worth implementing a workaround anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant