From d9dc2f22302d1e0b6cfc01522939a37dd2d8a4e6 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 18 Aug 2015 10:28:58 -0700 Subject: [PATCH] [dev.ssa] cmd/compile: fix string store rewrite Store ops now need their size in the auxint field. I missed this one. Change-Id: I050fd6b5b00579883731702c426edafa3a5f7561 Reviewed-on: https://go-review.googlesource.com/13682 Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/ssa/gen/generic.rules | 2 +- src/cmd/compile/internal/ssa/gen/rulegen.go | 2 +- src/cmd/compile/internal/ssa/rewritegeneric.go | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 75cd186a43..db66a457c3 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -88,7 +88,7 @@ (Load ptr mem) && t.IsString() -> (StringMake (Load ptr mem) (Load (OffPtr [config.PtrSize] ptr) mem)) (StringPtr (StringMake ptr _)) -> ptr (StringLen (StringMake _ len)) -> len -(Store dst str mem) && str.Type.IsString() -> (Store (OffPtr [config.PtrSize] dst) (StringLen str) (Store dst (StringPtr str) mem)) +(Store [2*config.PtrSize] dst str mem) && str.Type.IsString() -> (Store [config.PtrSize] (OffPtr [config.PtrSize] dst) (StringLen str) (Store [config.PtrSize] dst (StringPtr str) mem)) (If (IsNonNil (GetG)) yes no) -> (Plain nil yes) diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index 57305413f9..057e68601b 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -560,7 +560,7 @@ func unbalanced(s string) bool { // isVariable reports whether s is a single Go alphanumeric identifier. func isVariable(s string) bool { - b, err := regexp.MatchString("[A-Za-z_][A-Za-z_0-9]*", s) + b, err := regexp.MatchString("^[A-Za-z_][A-Za-z_0-9]*$", s) if err != nil { panic("bad variable regexp") } diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index a0c5269e2e..4c278cb168 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -906,20 +906,24 @@ func rewriteValuegeneric(v *Value, config *Config) bool { goto enda18a7163888e2f4fca9f38bae56cef42 enda18a7163888e2f4fca9f38bae56cef42: ; - // match: (Store dst str mem) + // match: (Store [2*config.PtrSize] dst str mem) // cond: str.Type.IsString() - // result: (Store (OffPtr [config.PtrSize] dst) (StringLen str) (Store dst (StringPtr str) mem)) + // result: (Store [config.PtrSize] (OffPtr [config.PtrSize] dst) (StringLen str) (Store [config.PtrSize] dst (StringPtr str) mem)) { + if v.AuxInt != 2*config.PtrSize { + goto end6942df62f9cb570a99ab97a5aeebfd2d + } dst := v.Args[0] str := v.Args[1] mem := v.Args[2] if !(str.Type.IsString()) { - goto enddf0c5a150f4b4bf6715fd2bd4bb4cc20 + goto end6942df62f9cb570a99ab97a5aeebfd2d } v.Op = OpStore v.AuxInt = 0 v.Aux = nil v.resetArgs() + v.AuxInt = config.PtrSize v0 := b.NewValue0(v.Line, OpOffPtr, TypeInvalid) v0.Type = config.Frontend().TypeBytePtr() v0.AuxInt = config.PtrSize @@ -930,6 +934,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool { v1.AddArg(str) v.AddArg(v1) v2 := b.NewValue0(v.Line, OpStore, TypeInvalid) + v2.AuxInt = config.PtrSize v2.Type = TypeMem v2.AddArg(dst) v3 := b.NewValue0(v.Line, OpStringPtr, TypeInvalid) @@ -940,8 +945,8 @@ func rewriteValuegeneric(v *Value, config *Config) bool { v.AddArg(v2) return true } - goto enddf0c5a150f4b4bf6715fd2bd4bb4cc20 - enddf0c5a150f4b4bf6715fd2bd4bb4cc20: + goto end6942df62f9cb570a99ab97a5aeebfd2d + end6942df62f9cb570a99ab97a5aeebfd2d: ; case OpStringLen: // match: (StringLen (StringMake _ len))