From 3294014ae119f34c40547ed253bf4c5d25dc5f17 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 4 Mar 2016 14:12:44 -0800 Subject: [PATCH] cmd/compile: collapse OffPtr sequences This triggers an astonishing 160k times during make.bash. The second biggest generic rewrite triggers 100k times. However, this is really just moving rewrites that were happening at the architecture level to the generic level. Change-Id: Ife06fe5234f31433328460cb2e0741c071deda41 Reviewed-on: https://go-review.googlesource.com/20235 Run-TryBot: Todd Neal TryBot-Result: Gobot Gobot Reviewed-by: Todd Neal --- .../compile/internal/ssa/gen/generic.rules | 3 +++ .../compile/internal/ssa/rewritegeneric.go | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 0c77a6dee8..994e880bc6 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -404,6 +404,9 @@ // Load of store of same address, with compatibly typed value and same size (Load p1 (Store [w] p2 x _)) && isSamePtr(p1,p2) && t1.Compare(x.Type)==CMPeq && w == t1.Size() -> x +// Collapse OffPtr +(OffPtr (OffPtr p [b]) [a]) -> (OffPtr p [a+b]) + // indexing operations // Note: bounds check has already been done diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 1ed5fa9555..79dcf9a716 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -206,6 +206,8 @@ func rewriteValuegeneric(v *Value, config *Config) bool { return rewriteValuegeneric_OpNeqPtr(v, config) case OpNeqSlice: return rewriteValuegeneric_OpNeqSlice(v, config) + case OpOffPtr: + return rewriteValuegeneric_OpOffPtr(v, config) case OpOr16: return rewriteValuegeneric_OpOr16(v, config) case OpOr32: @@ -4821,6 +4823,26 @@ func rewriteValuegeneric_OpNeqSlice(v *Value, config *Config) bool { } return false } +func rewriteValuegeneric_OpOffPtr(v *Value, config *Config) bool { + b := v.Block + _ = b + // match: (OffPtr (OffPtr p [b]) [a]) + // cond: + // result: (OffPtr p [a+b]) + for { + if v.Args[0].Op != OpOffPtr { + break + } + p := v.Args[0].Args[0] + b := v.Args[0].AuxInt + a := v.AuxInt + v.reset(OpOffPtr) + v.AddArg(p) + v.AuxInt = a + b + return true + } + return false +} func rewriteValuegeneric_OpOr16(v *Value, config *Config) bool { b := v.Block _ = b