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/compile: generic optimizations cannot remove load-hit-store on struct field #19164

mundaym opened this issue Feb 17, 2017 · 3 comments


None yet
4 participants
Copy link

commented Feb 17, 2017

On tip (ddb15ce) it looks like there is an opportunity for the generic optimizations to remove a load-hit-store of struct fields. They can't currently because for some reason the types of OffPtr are different for loads and stores. For example:

type t struct {
        v int8

func loadHitStore8(x int8, p *t) int32 {
        p.v = x
        return int32(p.v)

Compiles to:

    v1 = InitMem <mem>
    v2 = SP <uintptr>
    v3 = SB <uintptr> DEAD
    v4 = Addr <*int8> {x} v2 DEAD
    v5 = Addr <**t> {p} v2 DEAD
    v6 = Addr <*int32> {~r2} v2
    v7 = Arg <int8> {x}
    v8 = Arg <*t> {p}
    v9 = Const32 <int32> [0] DEAD
    v10 = NilCheck <void> v8 v1
    v11 = OffPtr <*int8> [0] v8 <----------- type = *int8
    v12 = Store <mem> [1] v11 v7 v1
    v13 = NilCheck <void> v8 v12
    v14 = OffPtr <*t> [0] v8 <-------------- type = *t
    v15 = Load <int8> v14 v12
    v16 = SignExt8to32 <int32> v15
    v17 = VarDef <mem> {~r2} v12
    v18 = Store <mem> [4] v6 v16 v17
    Ret v18

Since the types of v11 and v14 are different the generic rules can't tell that they are really the same pointer, and so cannot turn v15 into a Copy.


This comment has been minimized.

Copy link

commented Feb 17, 2017

Why isn't v14 being rewritten to v8?

(OffPtr [0] x) && x.Type == t -> x

v11 is still a problem.


This comment has been minimized.

Copy link
Member Author

commented Feb 17, 2017

It is later, this snapshot is before the optimization pass.


This comment has been minimized.

Copy link

commented Feb 19, 2017

CL mentions this issue.

@gopherbot gopherbot closed this in 10d718b Feb 21, 2017

@golang golang locked and limited conversation to collaborators Feb 21, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.