• Keith Randall's avatar
    cmd/compile: automatically handle commuting ops in rewrite rules · 041ecb69
    Keith Randall authored
    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.
    [Note to reviewers: check these carefully. Most of the other rule
    changes are trivial.]
    
    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: I999b1307272e91965b66754576019dedcbe7527a
    Reviewed-on: https://go-review.googlesource.com/38666
    Run-TryBot: Keith Randall <khr@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarDavid Chase <drchase@google.com>
    041ecb69
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
plugin Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...