Skip to content

cmd/compile: combine small loads #14267

Closed
@randall77

Description

@randall77

encoding/binary/binary.go:

func (littleEndian) Uint64(b []byte) uint64 {
    return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
        uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
}

It would be nice to combine the small loads into one larger load, at least for architectures with unaligned loads.

See #14266 for the bug about combining the bounds checks. This bug is about combining the loads themselves. We could use rewrite rules something like:

(Or64 (Load <t> ptr mem) (Shl64x64 (Load <t> (Add64 ptr (Const64 [t.Size()])) mem) (Const64 [8*t.Size()]))) -> (Load ptr mem)

These rules would probably work independent of whether the bounds checks are fixed or not.

Maybe we could do stores also. That would require the bounds checks to go first, and the user to write to the max index first (otherwise partial writes would be observable).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions