Skip to content

Commit e22ba7f

Browse files
committed
cmd/compile: enable CSE of constant strings
CL 27254 changed a constant string to a byte array in encoding/hex and got significant performance improvements. hex.Encode used the string twice in a single function. The rewrite rules lower constant strings into components. The pointer component requires an aux symbol. The existing implementation created a new aux symbol every time. As a result, constant string pointers were never CSE'd. Tighten then moved the pointer calculation next to the uses, i.e. into the loop. The re-use of aux syms enabled by this CL occurs 3691 times during make.bash. This CL should not go in without CL 38338 or something like it. Change-Id: Ibbf5b17283c0e31821d04c7e08d995c654de5663 Reviewed-on: https://go-review.googlesource.com/28219 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 25b5181 commit e22ba7f

File tree

1 file changed

+16
-9
lines changed
  • src/cmd/compile/internal/gc

1 file changed

+16
-9
lines changed

src/cmd/compile/internal/gc/ssa.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,17 +3104,16 @@ func etypesign(e EType) int8 {
31043104
func (s *state) lookupSymbol(n *Node, sym interface{}) interface{} {
31053105
switch sym.(type) {
31063106
default:
3107-
s.Fatalf("sym %v is of uknown type %T", sym, sym)
3107+
s.Fatalf("sym %v is of unknown type %T", sym, sym)
31083108
case *ssa.ExternSymbol, *ssa.ArgSymbol, *ssa.AutoSymbol:
31093109
// these are the only valid types
31103110
}
31113111

31123112
if lsym, ok := s.varsyms[n]; ok {
31133113
return lsym
3114-
} else {
3115-
s.varsyms[n] = sym
3116-
return sym
31173114
}
3115+
s.varsyms[n] = sym
3116+
return sym
31183117
}
31193118

31203119
// addr converts the address of the expression n to SSA, adds it to s and returns the SSA result.
@@ -4692,17 +4691,25 @@ func fieldIdx(n *Node) int {
46924691
// It also exports a bunch of compiler services for the ssa backend.
46934692
type ssafn struct {
46944693
curfn *Node
4695-
stksize int64 // stack size for current frame
4696-
stkptrsize int64 // prefix of stack containing pointers
4694+
strings map[string]interface{} // map from constant string to data symbols
4695+
stksize int64 // stack size for current frame
4696+
stkptrsize int64 // prefix of stack containing pointers
46974697
log bool
46984698
}
46994699

47004700
// StringData returns a symbol (a *Sym wrapped in an interface) which
47014701
// is the data component of a global string constant containing s.
4702-
func (*ssafn) StringData(s string) interface{} {
4703-
// TODO: is idealstring correct? It might not matter...
4702+
func (e *ssafn) StringData(s string) interface{} {
4703+
if aux, ok := e.strings[s]; ok {
4704+
return aux
4705+
}
4706+
if e.strings == nil {
4707+
e.strings = make(map[string]interface{})
4708+
}
47044709
data := stringsym(s)
4705-
return &ssa.ExternSymbol{Typ: idealstring, Sym: data}
4710+
aux := &ssa.ExternSymbol{Typ: idealstring, Sym: data}
4711+
e.strings[s] = aux
4712+
return aux
47064713
}
47074714

47084715
func (e *ssafn) Auto(t ssa.Type) ssa.GCNode {

0 commit comments

Comments
 (0)