aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/rewriteRISCV64.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2020-01-06 22:24:02 -0800
committerJosh Bleecher Snyder <josharian@gmail.com>2020-02-20 17:34:07 +0000
commitbd6d78ef37b5a607abfb530f3e353cfa653492f1 (patch)
treeb6093e2f6d6f82b4223b289cec5dae9730b0e3ff /src/cmd/compile/internal/ssa/rewriteRISCV64.go
parent631b49886c27f88c2d701176104b01b24e551d7c (diff)
downloadgo-bd6d78ef37b5a607abfb530f3e353cfa653492f1.tar.gz
go-bd6d78ef37b5a607abfb530f3e353cfa653492f1.zip
cmd/compile: use loops to handle commutative ops in rules
Prior to this change, we generated additional rules at rulegen time for all possible combinations of args to commutative ops. This is simple and works well, but leads to lots of generated rules. This in turn has increased the size of the compiler, made it hard to compile package ssa on small machines, and provided a disincentive to mark some ops as commutative. This change reworks how we handle commutative ops. Instead of generating a rule per argument permutation, we generate a series of nested loops, one for each commutative op. Each loop tries both possible argument orderings. I also considered attempting to canonicalize the inputs to the rewrite rules. However, because either or both arguments might be nothing more than an identifier, and because there can be arbitrary conditions to evaluate during matching, I did not see how to proceed. The duplicate rule detection now sorts arguments to commutative ops, so that it can detect commutative-only duplicates. There may be further optimizations to the new generated code. In particular, we may not be removing as many bounds checks as before; I have not investigated deeply. If more work here is needed, we could do it with more hints or with improvements to the prove pass. This change has almost no impact on the generated code. It does not pass toolstash-check, however. In a handful of functions, for reasons I do not understand, there are minor position changes. For the entire series ending at this change, there is negligible compiler performance impact. The compiler binary shrinks by about 15%, and package ssa shrinks by about 25%. Package ssa also compiles ~25% faster with ~25% less memory. Change-Id: Ia2ee9ceae7be08a17342319d4e31b0bb238a2ee4 Reviewed-on: https://go-review.googlesource.com/c/go/+/213703 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewriteRISCV64.go')
-rw-r--r--src/cmd/compile/internal/ssa/rewriteRISCV64.go45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
index 8ccfaa54f95..2c23609d488 100644
--- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go
+++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
@@ -3196,38 +3196,23 @@ func rewriteValueRISCV64_OpRISCV64ADD_0(v *Value) bool {
// cond: is32Bit(off)
// result: (ADDI [off] ptr)
for {
- ptr := v.Args[1]
- v_0 := v.Args[0]
- if v_0.Op != OpRISCV64MOVDconst {
- break
- }
- off := v_0.AuxInt
- if !(is32Bit(off)) {
- break
- }
- v.reset(OpRISCV64ADDI)
- v.AuxInt = off
- v.AddArg(ptr)
- return true
- }
- // match: (ADD ptr (MOVDconst [off]))
- // cond: is32Bit(off)
- // result: (ADDI [off] ptr)
- for {
_ = v.Args[1]
- ptr := v.Args[0]
- v_1 := v.Args[1]
- if v_1.Op != OpRISCV64MOVDconst {
- break
- }
- off := v_1.AuxInt
- if !(is32Bit(off)) {
- break
+ for _i0 := 0; _i0 <= 1; _i0++ {
+ v_0 := v.Args[_i0]
+ if v_0.Op != OpRISCV64MOVDconst {
+ continue
+ }
+ off := v_0.AuxInt
+ ptr := v.Args[1^_i0]
+ if !(is32Bit(off)) {
+ continue
+ }
+ v.reset(OpRISCV64ADDI)
+ v.AuxInt = off
+ v.AddArg(ptr)
+ return true
}
- v.reset(OpRISCV64ADDI)
- v.AuxInt = off
- v.AddArg(ptr)
- return true
+ break
}
return false
}