Skip to content

Commit

Permalink
cmd/compile: store combine on amd64
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie committed Aug 5, 2022
1 parent f32519e commit 03f1994
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
13 changes: 8 additions & 5 deletions src/cmd/compile/internal/ssa/gen/AMD64.rules
Expand Up @@ -2043,15 +2043,18 @@
&& clobber(x)
=> (MOVQstore [i] {s} p0 w0 mem)

(MOVBstore [7] {s} p1 (SHRQconst [56] w)
x1:(MOVWstore [5] {s} p1 (SHRQconst [40] w)
x2:(MOVLstore [1] {s} p1 (SHRQconst [8] w)
x3:(MOVBstore [0] {s} p1 w mem))))
(MOVBstore [c3] {s} p3 (SHRQconst [56] w)
x1:(MOVWstore [c2] {s} p2 (SHRQconst [40] w)
x2:(MOVLstore [c1] {s} p1 (SHRQconst [8] w)
x3:(MOVBstore [c0] {s} p0 w mem))))
&& x1.Uses == 1
&& x2.Uses == 1
&& x3.Uses == 1
&& sequentialAddresses(p0, p1, int64(1 + c0 - c1))
&& sequentialAddresses(p0, p2, int64(5 + c0 - c2))
&& sequentialAddresses(p0, p3, int64(7 + c0 - c3))
&& clobber(x1, x2, x3)
=> (MOVQstore {s} p1 w mem)
=> (MOVQstore [c0] {s} p0 w mem)

(MOVBstore [i] {s} p
x1:(MOVBload [j] {s2} p2 mem)
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/ssa/rewrite.go
Expand Up @@ -1764,6 +1764,9 @@ func read64(sym interface{}, off int64, byteorder binary.ByteOrder) uint64 {

// sequentialAddresses reports true if it can prove that x + n == y
func sequentialAddresses(x, y *Value, n int64) bool {
if x == y && n == 0 {
return true
}
if x.Op == Op386ADDL && y.Op == Op386LEAL1 && y.AuxInt == n && y.Aux == nil &&
(x.Args[0] == y.Args[0] && x.Args[1] == y.Args[1] ||
x.Args[0] == y.Args[1] && x.Args[1] == y.Args[0]) {
Expand Down
40 changes: 24 additions & 16 deletions src/cmd/compile/internal/ssa/rewriteAMD64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/codegen/memcombine.go
Expand Up @@ -369,6 +369,14 @@ func store_le64_idx(b []byte, x uint64, idx int) {
binary.LittleEndian.PutUint64(b[idx:], x)
}

func store_le64_idx2(dst []byte, d, length, offset int) []byte {
a := dst[d : d+length]
b := dst[d-offset:]
// amd64:`MOVQ\s.*\(.*\)\(.*\*1\)$`,-`SHR.`
binary.LittleEndian.PutUint64(a, binary.LittleEndian.Uint64(b))
return dst
}

func store_le64_load(b []byte, x *[8]byte) {
_ = b[8]
// amd64:-`MOV[BWL]`
Expand Down

0 comments on commit 03f1994

Please sign in to comment.