From: Josh Bleecher Snyder Date: Tue, 21 Jan 2020 03:42:11 +0000 (-0800) Subject: cmd/compile: document non-commutative rule detection X-Git-Tag: go1.15beta1~1171 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2dfdd85c4f3a5ca1b127644e8c7c6b2ba5a89bca;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index 7c6e1b29dd..47cf5f15da 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -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 } }