aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/rewritedec.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2017-03-30 03:30:22 +0000
committerKeith Randall <khr@golang.org>2017-04-03 22:03:43 +0000
commit53f8a6aeb089f981c9d4fc7871ef712d1669d0a4 (patch)
tree1137767d0b6ec8cc7c53b58fe153caf07dc9b621 /src/cmd/compile/internal/ssa/rewritedec.go
parent63a72fd447abb8a07bee9166e87bfe27780492c3 (diff)
downloadgo-53f8a6aeb089f981c9d4fc7871ef712d1669d0a4.tar.gz
go-53f8a6aeb089f981c9d4fc7871ef712d1669d0a4.zip
cmd/compile: automatically handle commuting ops in rewrite rules
Note that this is a redo of an undo of the original buggy CL 38666. We have lots of rewrite rules that vary only in the fact that we have 2 versions for the 2 different orderings of various commuting ops. For example: (ADDL x (MOVLconst [c])) -> (ADDLconst [c] x) (ADDL (MOVLconst [c]) x) -> (ADDLconst [c] x) It can get unwieldly quickly, especially when there is more than one commuting op in a rule. Our existing "fix" for this problem is to have rules that canonicalize the operations first. For example: (Eq64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Eq64 (Const64 <t> [c]) x) Subsequent rules can then assume if there is a constant arg to Eq64, it will be the first one. This fix kinda works, but it is fragile and only works when we remember to include the required extra rules. The fundamental problem is that the rule matcher doesn't know anything about commuting ops. This CL fixes that fact. We already have information about which ops commute. (The register allocator takes advantage of commutivity.) The rule generator now automatically generates multiple rules for a single source rule when there are commutative ops in the rule. We can now drop all of our almost-duplicate source-level rules and the canonicalization rules. I have some CLs in progress that will be a lot less verbose when the rule generator handles commutivity for me. I had to reorganize the load-combining rules a bit. The 8-way OR rules generated 128 different reorderings, which was causing the generator to put too much code in the rewrite*.go files (the big ones were going from 25K lines to 132K lines). Instead I reorganized the rules to combine pairs of loads at a time. The generated rule files are now actually a bit (5%) smaller. Make.bash times are ~unchanged. Compiler benchmarks are not observably different. Probably because we don't spend much compiler time in rule matching anyway. I've also done a pass over all of our ops adding commutative markings for ops which hadn't had them previously. Fixes #18292 Change-Id: Ic1c0e43fbf579539f459971625f69690c9ab8805 Reviewed-on: https://go-review.googlesource.com/38801 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewritedec.go')
-rw-r--r--src/cmd/compile/internal/ssa/rewritedec.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/ssa/rewritedec.go b/src/cmd/compile/internal/ssa/rewritedec.go
index 539c05d4d9..9c99b83070 100644
--- a/src/cmd/compile/internal/ssa/rewritedec.go
+++ b/src/cmd/compile/internal/ssa/rewritedec.go
@@ -36,7 +36,7 @@ func rewriteValuedec(v *Value) bool {
return false
}
func rewriteValuedec_OpComplexImag(v *Value) bool {
- // match: (ComplexImag (ComplexMake _ imag ))
+ // match: (ComplexImag (ComplexMake _ imag))
// cond:
// result: imag
for {
@@ -53,7 +53,7 @@ func rewriteValuedec_OpComplexImag(v *Value) bool {
return false
}
func rewriteValuedec_OpComplexReal(v *Value) bool {
- // match: (ComplexReal (ComplexMake real _ ))
+ // match: (ComplexReal (ComplexMake real _))
// cond:
// result: real
for {
@@ -276,7 +276,7 @@ func rewriteValuedec_OpSliceLen(v *Value) bool {
return false
}
func rewriteValuedec_OpSlicePtr(v *Value) bool {
- // match: (SlicePtr (SliceMake ptr _ _ ))
+ // match: (SlicePtr (SliceMake ptr _ _))
// cond:
// result: ptr
for {