Skip to content

cmd/compile: stores to unused variables on the stack not eliminated #19765

Closed

Description

@mundaym

I am trying to replace math.Float64bits and friends with register to register moves and noticed that stores to variables on the stack aren't eliminated when their all their uses have been optimized away. Is there an existing issue for this?

For example, on tip (6e9ec14):

package main

var Sink int

func main() {
	x := 1
	Sink = *(&x)
}

Compiles to:

   	00000 (/tmp/main.go:5)	TEXT	"".main(SB)
   	00001 (/tmp/main.go:5)	FUNCDATA	$0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
   	00002 (/tmp/main.go:5)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
v7	00003 (/tmp/main.go:6)	MOVQ	$1, "".x-8(SP)
v13	00004 (/tmp/main.go:7)	MOVQ	$1, "".Sink(SB)
b1	00005 (/tmp/main.go:8)	RET
   	00006 (<unknown line number>)	END

The MOVQ $1, "".x-8(SP) could be eliminated by the compiler but isn't.

Activity

  1. randall77 commented on Mar 29, 2017

    @randall77
    Contributor

    Kind of a dup of #13095

  2. gopherbot commented on Mar 29, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/38746 mentions this issue.

  3. locked and limited conversation to collaborators on Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions