You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: js-wasm builder broke on "isfat" optimization #33916
https://go-review.googlesource.com/c/go/+/179578 changed plive.go's "isfat" function to treat single element arrays and single field structs as single-value objects rather than multi-value objects. The notable thing about this change is it means for things like:
var x struct { m *blah }
x.m = foo()
the x.m = foo() assignment is considered as clobbering x, whereas before it was treated as just updating a single field, so the variable was considered live.
The CL updated test expectations accordingly, but the js-wasm builder seemed to fail on these, as it still considered the struct live in some cases.
The CL has been reverted, but I think it would be good to understand why only js-wasm failed and land the change again.
I see. So in live2.go's bad40, immediately before SSA lowering, we have (v25 is the return value from makemap, and v23 is the mem object returned by it):
I think wasm should switch to support SymOffset for its load and store operations like other GOARCHes.
It seems like the reason this isn't a bigger issue for wasm is that gc/ssa.go inserts OpVarDef instructions around assignments where possible. This issue came up because it introduced new cases where plive.go was able to detect a variable was dead where gc/ssa.go didn't notice.
So an alternative fix here would be to extend gc/ssa.go to incorporate the "isfat" logic for figuring out when it can insert OpVarDef.
gc/ssa.go emits OpVarDef when an assignments overwrites the entire variable. Currently it does this when an object is declared, and also immediately before assignments that overwrite the entire object (eg, x = ...). Note: OpVarDef can be emitted multiple times for a single variable.
The alternative suggestion I was making was that gc/ssa.go should also recognize x.m = ... assignments where x's type is not "fat".
Also where must we incorporate the "isfat" logic?
I would expect it would just be a tweak to the existing OpVarDef logic in builder.assign.
gc/ssa.go emits OpVarDef when an assignments overwrites the entire variable. Currently it does this when an object is declared, and also immediately before assignments that overwrite the entire object (eg, x = ...). Note: OpVarDef can be emitted multiple times for a single variable.
The alternative suggestion I was making was that gc/ssa.go should also recognize x.m = ... assignments where x's type is not "fat".
Also where must we incorporate the "isfat" logic?
I would expect it would just be a tweak to the existing OpVarDef logic in builder.assign.
Hmm, the same as I did, but still no luck, maybe I check the wrong place, let me re-check.
Activity
mdempsky commentedon Aug 28, 2019
I think the problem is that ssa/gen/WasmOps.go doesn't annotate instructions with symEffect.
I'm kind of surprised there aren't more liveness issues on GOARCH=wasm.
mdempsky commentedon Aug 28, 2019
I see. So in live2.go's bad40, immediately before SSA lowering, we have (v25 is the return value from makemap, and v23 is the mem object returned by it):
On most architectures (I tested amd64 and arm64, and I expect others are the same), this gets lowered to something like:
Critically, plive.go is able to recognize than this MOVQ clobbers
retbecause MOVQstore is annotated withsymEffect: "write"in gen/AMD64Ops.go.However, on wasm, this gets lowered to:
which I think is roughly comparable to something like:
That is, the address computation is split out separately, and plive.go can't figure out the store is clobbering anything.
I think wasm should switch to support SymOffset for its load and store operations like other GOARCHes.
/cc @randall77 @cherrymui @neelance
mdempsky commentedon Aug 28, 2019
It seems like the reason this isn't a bigger issue for wasm is that gc/ssa.go inserts OpVarDef instructions around assignments where possible. This issue came up because it introduced new cases where plive.go was able to detect a variable was dead where gc/ssa.go didn't notice.
So an alternative fix here would be to extend gc/ssa.go to incorporate the "isfat" logic for figuring out when it can insert
OpVarDef.cuonglm commentedon Aug 29, 2019
@mdempsky IIRC, buildssa emits OpVarDef regardless of variable is fat or not.
mdempsky commentedon Aug 29, 2019
For assignments like
x = ...it does, but I don't believe that's the case for subvariable assignments likex.m = ....cherrymui commentedon Aug 31, 2019
I think this makes sense, at least for local variables.
cuonglm commentedon Sep 3, 2019
@mdempsky can you describe it more details?
Looking at SSA output, I see
OpVarDefwas inserted whenretdeclared. Also where must we incorporate the "isfat" logic?mdempsky commentedon Sep 3, 2019
gc/ssa.go emits OpVarDef when an assignments overwrites the entire variable. Currently it does this when an object is declared, and also immediately before assignments that overwrite the entire object (eg,
x = ...). Note: OpVarDef can be emitted multiple times for a single variable.The alternative suggestion I was making was that gc/ssa.go should also recognize
x.m = ...assignments where x's type is not "fat".I would expect it would just be a tweak to the existing OpVarDef logic in builder.assign.
cuonglm commentedon Sep 3, 2019
Hmm, the same as I did, but still no luck, maybe I check the wrong place, let me re-check.
gopherbot commentedon Sep 3, 2019
Change https://golang.org/cl/192978 mentions this issue:
Revert "Revert "cmd/compile: make isfat handle 1-element array, 1-field struct""gopherbot commentedon Sep 3, 2019
Change https://golang.org/cl/192979 mentions this issue:
cmd/compile: extend ssa.go to incorporate the "isfat" logiccmd/compile: extend ssa.go to handle 1-element array and 1-field struct