import (
"cmd/compile/internal/ir"
"cmd/compile/internal/types"
+ "cmd/internal/obj"
)
// dse does dead-store elimination on the Function.
case OpAddr, OpLocalAddr:
// Propagate the address if it points to an auto.
n, ok := v.Aux.(*ir.Name)
- if !ok || n.Class != ir.PAUTO {
+ if !ok || (n.Class != ir.PAUTO && !isABIInternalParam(f, n)) {
return
}
if addr[v] == nil {
case OpVarDef:
// v should be eliminated if we eliminate the auto.
n, ok := v.Aux.(*ir.Name)
- if !ok || n.Class != ir.PAUTO {
+ if !ok || (n.Class != ir.PAUTO && !isABIInternalParam(f, n)) {
return
}
if elim[v] == nil {
// may not be used by the inline code, but will be used by
// panic processing).
n, ok := v.Aux.(*ir.Name)
- if !ok || n.Class != ir.PAUTO {
+ if !ok || (n.Class != ir.PAUTO && !isABIInternalParam(f, n)) {
return
}
if !used.Has(n) {
if !ok {
continue
}
- if n.Class != ir.PAUTO {
+ if n.Class != ir.PAUTO && !isABIInternalParam(f, n) {
continue
}
store.Op = OpCopy
}
}
+
+// isABIInternalParam returns whether n is a parameter of an ABIInternal
+// function. For dead store elimination, we can treat parameters the same
+// way as autos. Storing to a parameter can be removed if it is not read
+// or address-taken.
+//
+// We check ABI here because for a cgo_unsafe_arg function (which is ABI0),
+// all the args are effectively address-taken, but not necessarily have
+// an Addr or LocalAddr op. We could probably just check for cgo_unsafe_arg,
+// but ABIInternal is mostly what matters.
+func isABIInternalParam(f *Func, n *ir.Name) bool {
+ return n.Class == ir.PPARAM && f.ABISelf.Which() == obj.ABIInternal
+}