From d337e55672c0ea6c29af2615e5fa345941f822c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20Mo=C8=99oi?= Date: Tue, 23 Feb 2016 21:48:33 +0100 Subject: [PATCH] [dev.ssa] cmd/compile/internal/ssa: simplify convert in more cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Saves about 2k for binaries in pkg/tool/linux_amd64. Also useful when opt runs after cse (as in 12960) which reorders arguments for commutative operations such as Add64. Change-Id: I49ad53afa53db9736bd35c425f4fb35fb511fd63 Reviewed-on: https://go-review.googlesource.com/19827 Run-TryBot: Alexandru Moșoi TryBot-Result: Gobot Gobot Reviewed-by: David Chase Reviewed-by: Keith Randall --- .../compile/internal/ssa/gen/generic.rules | 1 + .../compile/internal/ssa/rewritegeneric.go | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 4d431055573..ac243379205 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -586,6 +586,7 @@ // Get rid of Convert ops for pointer arithmetic on unsafe.Pointer. (Convert (Add64 (Convert ptr mem) off) mem) -> (Add64 ptr off) +(Convert (Add64 off (Convert ptr mem)) mem) -> (Add64 ptr off) (Convert (Convert ptr mem) mem) -> ptr // Decompose compound argument values diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 7916c6d8f41..08ab2e14a62 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -1428,6 +1428,27 @@ func rewriteValuegeneric_OpConvert(v *Value, config *Config) bool { v.AddArg(off) return true } + // match: (Convert (Add64 off (Convert ptr mem)) mem) + // cond: + // result: (Add64 ptr off) + for { + if v.Args[0].Op != OpAdd64 { + break + } + off := v.Args[0].Args[0] + if v.Args[0].Args[1].Op != OpConvert { + break + } + ptr := v.Args[0].Args[1].Args[0] + mem := v.Args[0].Args[1].Args[1] + if v.Args[1] != mem { + break + } + v.reset(OpAdd64) + v.AddArg(ptr) + v.AddArg(off) + return true + } // match: (Convert (Convert ptr mem) mem) // cond: // result: ptr