diff options
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewrite.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewrite.go | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index fb35691296..09f94ef53e 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -20,7 +20,15 @@ import ( "path/filepath" ) -func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) { +type deadValueChoice bool + +const ( + leaveDeadValues deadValueChoice = false + removeDeadValues = true +) + +// deadcode indicates that rewrite should try to remove any values that become dead. +func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValueChoice) { // repeat rewrites until we find no more rewrites pendingLines := f.cachedLineStarts // Holds statement boundaries that need to be moved to a new value/block pendingLines.clear() @@ -56,6 +64,18 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) { *v0 = *v v0.Args = append([]*Value{}, v.Args...) // make a new copy, not aliasing } + if v.Uses == 0 && v.removeable() { + if v.Op != OpInvalid && deadcode == removeDeadValues { + // Reset any values that are now unused, so that we decrement + // the use count of all of its arguments. + // Not quite a deadcode pass, because it does not handle cycles. + // But it should help Uses==1 rules to fire. + v.reset(OpInvalid) + change = true + } + // No point rewriting values which aren't used. + continue + } vchange := phielimValue(v) if vchange && debug > 1 { @@ -631,6 +651,10 @@ func auxIntToFlagConstant(x int64) flagConstant { return flagConstant(x) } +func auxIntToOp(cc int64) Op { + return Op(cc) +} + func boolToAuxInt(b bool) int64 { if b { return 1 @@ -674,6 +698,10 @@ func flagConstantToAuxInt(x flagConstant) int64 { return int64(x) } +func opToAuxInt(o Op) int64 { + return int64(o) +} + func auxToString(i interface{}) string { return i.(string) } @@ -707,13 +735,6 @@ func s390xCCMaskToAux(c s390x.CCMask) interface{} { func s390xRotateParamsToAux(r s390x.RotateParams) interface{} { return r } -func cCopToAux(o Op) interface{} { - return o -} - -func auxToCCop(cc interface{}) Op { - return cc.(Op) -} // uaddOvf reports whether unsigned a+b would overflow. func uaddOvf(a, b int64) bool { |