Skip to content

Commit

Permalink
cmd/compile: absorb more Not ops into Neq* and Eq* ops
Browse files Browse the repository at this point in the history
We absorbed Not into most integer comparisons but not into pointer
and floating point equality checks.

The new cases trigger more than 300 times during make.bash.

Change-Id: I77c6b31fcacde10da5470b73fc001a19521ce78d
Reviewed-on: https://go-review.googlesource.com/c/go/+/200618
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
  • Loading branch information
mundaym committed Nov 4, 2019
1 parent 26d5f03 commit bb7890b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/ssa/gen/generic.rules
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@
(Sub8 x (Const8 <t> [c])) && x.Op != OpConst8 -> (Add8 (Const8 <t> [int64(int8(-c))]) x)

// fold negation into comparison operators
(Not (Eq(64|32|16|8|B) x y)) -> (Neq(64|32|16|8|B) x y)
(Not (Neq(64|32|16|8|B) x y)) -> (Eq(64|32|16|8|B) x y)
(Not (Eq(64|32|16|8|B|Ptr|64F|32F) x y)) -> (Neq(64|32|16|8|B|Ptr|64F|32F) x y)
(Not (Neq(64|32|16|8|B|Ptr|64F|32F) x y)) -> (Eq(64|32|16|8|B|Ptr|64F|32F) x y)

(Not (Greater(64|32|16|8) x y)) -> (Leq(64|32|16|8) x y)
(Not (Greater(64|32|16|8)U x y)) -> (Leq(64|32|16|8)U x y)
Expand All @@ -273,7 +273,6 @@
(Not (Leq(64|32|16|8) x y)) -> (Greater(64|32|16|8) x y)
(Not (Leq(64|32|16|8)U x y)) -> (Greater(64|32|16|8)U x y)


// Distribute multiplication c * (d+x) -> c*d + c*x. Useful for:
// a[i].b = ...; a[i+1].b = ...
(Mul64 (Const64 <t> [c]) (Add64 <t> (Const64 <t> [d]) x)) ->
Expand Down
108 changes: 96 additions & 12 deletions src/cmd/compile/internal/ssa/rewritegeneric.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb7890b

Please sign in to comment.