cmd/compile: document non-commutative rule detection

This documentation was lost in CL 213703.
This change restores it.

Change-Id: I544f15771d8a7390893efbda93478b46095ccf3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/215541
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2020-01-20 19:42:11 -08:00
parent b28a07e75f
commit 2dfdd85c4f
1 changed files with 7 additions and 0 deletions

View File

@ -966,9 +966,16 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string, cnt map[string]int)
commutative := op.commutative
if commutative {
if args[0] == args[1] {
// When we have (Add x x), for any x,
// even if there are other uses of x besides these two,
// and even if x is not a variable,
// we can skip the commutative match.
commutative = false
}
if cnt[args[0]] == 1 && cnt[args[1]] == 1 {
// When we have (Add x y) with no other uses
// of x and y in the matching rule and condition,
// then we can skip the commutative match (Add y x).
commutative = false
}
}