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

cmd/gc: optimize assignment of empty string literals #7014

Closed
dvyukov opened this issue Dec 26, 2013 · 1 comment
Closed

cmd/gc: optimize assignment of empty string literals #7014

dvyukov opened this issue Dec 26, 2013 · 1 comment

Comments

@dvyukov
Copy link
Member

dvyukov commented Dec 26, 2013

Currently gc generates the following code:

    var s1 string
  400c19:   48 c7 44 24 08 00 00    movq   $0x0,0x8(%rsp)
  400c22:   48 c7 44 24 10 00 00    movq   $0x0,0x10(%rsp)

    s2 := ""
  400c2b:   48 8d 1c 25 20 63 42    lea    0x426320,%rbx
  400c33:   48 8b 2b                mov    (%rbx),%rbp
  400c36:   48 89 6c 24 18          mov    %rbp,0x18(%rsp)
  400c3b:   48 8b 6b 08             mov    0x8(%rbx),%rbp
  400c3f:   48 89 6c 24 20          mov    %rbp,0x20(%rsp)

    s3 = ""
  400c44:   48 8d 1c 25 20 63 42    lea    0x426320,%rbx
  400c4c:   48 8b 2b                mov    (%rbx),%rbp
  400c4f:   48 89 2c 25 f0 34 46    mov    %rbp,0x4634f0
  400c57:   48 8b 6b 08             mov    0x8(%rbx),%rbp
  400c5b:   48 89 2c 25 f8 34 46    mov    %rbp,0x4634f8

Ideally it is:

    var s1 string
  400c19:   48 c7 44 24 08 00 00    movq   $0x0,0x8(%rsp)
  400c22:   48 c7 44 24 10 00 00    movq   $0x0,0x10(%rsp)

    s2 := ""
  400c19:   48 c7 44 24 08 00 00    movq   $0x0,0x8(%rsp)
  400c22:   48 c7 44 24 10 00 00    movq   $0x0,0x10(%rsp)

    s3 = ""
  400c19:   48 c7 44 24 08 00 00    movq   $0x0,0x8(%rsp)
  400c22:   48 c7 44 24 10 00 00    movq   $0x0,0x10(%rsp)

For := "", compiler can just remove the initializer.
For = "", compiler can recognize "" and store zeros.
@rsc
Copy link
Contributor

rsc commented Mar 3, 2014

Comment 1:

Status changed to Duplicate.

Merged into issue #1914.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants