Skip to content

cmd/compile: no way to hint to eliminate bounds checks in bvec.AndNot #20393

@josharian

Description

@josharian

From cmd/compile/internal/gc/bv.go:

func (dst bvec) AndNot(src1, src2 bvec) {
	for i, x := range src1.b {
		dst.b[i] = x &^ src2.b[i]
	}
}

This can be very hot code for certain kind of input code. The core loop here contains two bounds checks, on dst.b[i] and src2.b[i]. By construction, though, len(dst.b) == len(src1.b) == len(src2.b).

The compiler should already have enough information to hoist these bounds checks out of the loop. I'd be happy enough to provide explicit hints, though, e.g. like _ = dst.b[len(src1.b)-1] at the top of the function. I'm not too particular about what they look like--I just want it to be possible. It doesn't appear to be right now; at least, I can't figure it out.

cc @brtzsnr @dr2chase

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions