]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: generate constants for NeqPtr, EqPtr and IsNonNil ops
authorMichael Munday <mike.munday@ibm.com>
Thu, 12 Apr 2018 14:24:08 +0000 (15:24 +0100)
committerMichael Munday <mike.munday@ibm.com>
Mon, 16 Apr 2018 20:43:57 +0000 (20:43 +0000)
commit58cdecb9c8d04d7eb1209d2877d541d34e23c9d3
tree8197fada4944867509fbd2e66563a49fdbf44008
parent89d576c933442ce0e3e78686db17a05de0a3dc8c
cmd/compile: generate constants for NeqPtr, EqPtr and IsNonNil ops

If both inputs are constant offsets from the same pointer then we
can evaluate NeqPtr and EqPtr at compile time. Triggers a few times
during all.bash. Removes a conditional branch in the following
code:

copy(x[1:], x[:])

This branch was recently added as an optimization in CL 94596. We
now skip the memmove if the pointers are equal. However, in the
above code we know at compile time that they are never equal.

Also, when the offset is variable, check if the offset is zero
rather than if the pointers are equal. For example:

copy(x[a:], x[:])

This would now skip the copy if a == 0, rather than if x + a == x.

Finally I've also added a rule to make IsNonNil true for pointers
to values on the stack. The nil check elimination pass will catch
these anyway, but eliminating them here might eliminate branches
earlier.

Change-Id: If72f436fef0a96ad0f4e296d3a1f8b6c3e712085
Reviewed-on: https://go-review.googlesource.com/106635
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
test/codegen/copy.go [moved from test/codegen/movesmall.go with 56% similarity]