]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: more negation related generic SSA rewrite rules
authorJorropo <jorropo.pgm@gmail.com>
Mon, 18 Apr 2022 17:46:43 +0000 (17:46 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 19 Apr 2022 22:24:44 +0000 (22:24 +0000)
commite858c14f916d424b33ad7e2450895b3117a5f727
tree0b9ab1a20cb831faf899a2c1a0e37b613b200545
parentaa8262d800f0cba2e4d4472a7e344eb60481b0ff
cmd/compile: more negation related generic SSA rewrite rules

The x + (-y) => x - y rule is hitted 75 times while building stage 3 and tools
and make the linux-amd64 go binary 0.007% smaller.
It transform:
  NEG AX
  ADD BX, AX
Into:
  SUB BX, AX
Which is 2X faster (assuming this assembly in a vacum).

The x ^ (-1) => ^x rule is not hitted in the toolchain.
It transforms:
  XOR $-1, AX
Into:
  NOT AX
Which is more compact as it doesn't encode the immediate.
Cache usage aside, this does not affect performance
(assuming this assembly in a vacum).
On my ryzen 3600, with some surrouding code, this randomly might be 2X faster,
I guess this has to do with loading the immediate into a temporary register.
Combined to an other rule that already exists it also rewrite manual two's
complement negation from:
  XOR $-1, AX
  INC AX
Into:
  NEG AX
Which is 2X faster.

The other rules just eliminates similar trivial cases and help constants
folding.

This should generalise to other architectures.

Change-Id: Ia1e51b340622e7ed88e5d856f3b1aa424aa039de
GitHub-Last-Rev: ce35ff2efdd8911f1e812806ec41a41e8cabc4c7
GitHub-Pull-Request: golang/go#52395
Reviewed-on: https://go-review.googlesource.com/c/go/+/400714
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go