From 6042a062dc2556a0a1c06d3b85b6c080644da04e Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 9 May 2023 13:25:40 -0700 Subject: cmd/compile: make memcombine pass a bit more robust to reassociation of exprs Be more liberal about expanding the OR tree. Handle any tree shape instead of a fully left or right associative tree. Also remove tail feature, it isn't ever needed. Change-Id: If16bebef94b952a604d6069e9be3d9129994cb6f Reviewed-on: https://go-review.googlesource.com/c/go/+/494056 TryBot-Result: Gopher Robot Run-TryBot: Keith Randall Reviewed-by: Ryan Berger Reviewed-by: Keith Randall Reviewed-by: David Chase --- test/codegen/memcombine.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/codegen') diff --git a/test/codegen/memcombine.go b/test/codegen/memcombine.go index c7a2c7e5ac..0d1c390dfc 100644 --- a/test/codegen/memcombine.go +++ b/test/codegen/memcombine.go @@ -338,6 +338,32 @@ func load_be_byte8_uint64_idx8(s []byte, idx int) uint64 { return uint64(s[idx<<3])<<56 | uint64(s[(idx<<3)+1])<<48 | uint64(s[(idx<<3)+2])<<40 | uint64(s[(idx<<3)+3])<<32 | uint64(s[(idx<<3)+4])<<24 | uint64(s[(idx<<3)+5])<<16 | uint64(s[(idx<<3)+6])<<8 | uint64(s[(idx<<3)+7]) } +// Some tougher cases for the memcombine pass. + +func reassoc_load_uint32(b []byte) uint32 { + // amd64:`MOVL\s\([A-Z]+\)`,-`MOV[BW]`,-`OR` + return (uint32(b[0]) | uint32(b[1])<<8) | (uint32(b[2])<<16 | uint32(b[3])<<24) +} + +func extrashift_load_uint32(b []byte) uint32 { + // amd64:`MOVL\s\([A-Z]+\)`,`SHLL\s[$]2`,-`MOV[BW]`,-`OR` + return uint32(b[0])<<2 | uint32(b[1])<<10 | uint32(b[2])<<18 | uint32(b[3])<<26 + +} + +func outoforder_load_uint32(b []byte) uint32 { + // amd64:`MOVL\s\([A-Z]+\)`,-`MOV[BW]`,-`OR` + return uint32(b[0]) | uint32(b[2])<<16 | uint32(b[1])<<8 | uint32(b[3])<<24 +} + +func extraOr_load_uint32(b []byte, x, y uint32) uint32 { + // amd64:`ORL\s\([A-Z]+\)`,-`MOV[BW]` + return x | binary.LittleEndian.Uint32(b) | y + // TODO: Note that + // x | uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 | y + // doesn't work because it associates in a way that memcombine can't detect it. +} + // Check load combining across function calls. func fcall_byte(a [2]byte) [2]byte { -- cgit v1.3-5-g9baa