In the SSA backend, we could optimize a call to runtime.memequal in which the length is small and one argument points to a readonly data symbol. We could replace it by reading the readonly data and checking the bytes of the other argument directly.
This is similar to the optimization in walk.go for comparing against a constant string, and could potentially supercede it. The optimization in walk.go doesn't always trigger. An example is using strings.HasPrefix to check for a constant prefix; the call gets inlined, but walk.go isn't able to do the optimization because its analysis isn't powerful enough.
The text was updated successfully, but these errors were encountered:
The path to resolution is known, but the work has not been done.
Feedback is required from experts, contributors, and/or the community before a change can be made.
Feb 18, 2020
This CL adds late expanded memequal(x, const, sz) inlining for 2, 4, 8
bytes size. This PoC is using the same method as CL 248404.
This optimization fires about 100 times in Go compiler (1675 occurrences
reduced to 1574, so -6%).
Also, added unit-tests to codegen/comparisions.go file.
Reviewed-by: Cherry Mui <firstname.lastname@example.org>
Run-TryBot: Cherry Mui <email@example.com>
Trust: David Chase <firstname.lastname@example.org>