diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2014-05-09 09:55:17 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2014-05-09 09:55:17 -0700 |
commit | 6988a86327f935152ad593451d69794a49f83966 (patch) | |
tree | dcad976cf268eb4eaa69ae835c955f3ef8a102d6 /src/cmd/5g | |
parent | 0098aa8b97feb00ccd1b02b6c976cd4092d085d4 (diff) | |
download | go-6988a86327f935152ad593451d69794a49f83966.tar.gz |
cmd/gc: don't give credit for NOPs during register allocation
The register allocator decides which variables should be placed into registers by charging for each load/store and crediting for each use, and then selecting an allocation with minimal cost. NOPs will be eliminated, however, so using a variable in a NOP should not generate credit.
Issue 7867 arises from attempted registerization of multi-word variables because they are used in NOPs. By not crediting for that use, they will no longer be considered for registerization.
This fix could theoretically lead to better register allocation, but NOPs are rare relative to other instructions.
Fixes issue 7867.
LGTM=rsc
R=rsc
CC=golang-codereviews
https://codereview.appspot.com/94810044
Diffstat (limited to 'src/cmd/5g')
-rw-r--r-- | src/cmd/5g/reg.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/cmd/5g/reg.c b/src/cmd/5g/reg.c index b4032fff8..80a14db3c 100644 --- a/src/cmd/5g/reg.c +++ b/src/cmd/5g/reg.c @@ -1097,18 +1097,20 @@ paint1(Reg *r, int bn) r->act.b[z] |= bb; p = r->f.prog; - if(r->use1.b[z] & bb) { - change += CREF * r->f.loop; - if(debug['R'] > 1) - print("%d%P\tu1 %Q $%d\n", r->f.loop, - p, blsh(bn), change); - } - if((r->use2.b[z]|r->set.b[z]) & bb) { - change += CREF * r->f.loop; - if(debug['R'] > 1) - print("%d%P\tu2 %Q $%d\n", r->f.loop, - p, blsh(bn), change); + if(r->f.prog->as != ANOP) { // don't give credit for NOPs + if(r->use1.b[z] & bb) { + change += CREF * r->f.loop; + if(debug['R'] > 1) + print("%d%P\tu1 %Q $%d\n", r->f.loop, + p, blsh(bn), change); + } + if((r->use2.b[z]|r->set.b[z]) & bb) { + change += CREF * r->f.loop; + if(debug['R'] > 1) + print("%d%P\tu2 %Q $%d\n", r->f.loop, + p, blsh(bn), change); + } } if(STORE(r) & r->regdiff.b[z] & bb) { |