Skip to content

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

@mundaym

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.

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