scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit ced6abe311cb8e3d553409e861f16fb7d64652cf
parent 2d870333e1b1f5383fe75996469bab34bf3aa97d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  3 Nov 2021 05:43:59 +0100

cc2/qbe: Use sethi number to drive assign generation

Sethi numbers gives an indication of the number of registers
needed to implement a tree, and generating first the subtree
with an higher sethi number improves the performance of  the
generated code.

Diffstat:
Msrc/cmd/cc/cc2/target/qbe/cgen.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -585,9 +585,14 @@ rhs(Node *np, Node *ret) l = l->left; } case 0: - /* TODO: see what is the most difficult */ - lhs(l, &aux2); - rhs(r, ret); + if (l->complex >= r->complex) { + lhs(l, &aux2); + rhs(r, ret); + } else { + rhs(r, ret); + lhs(l, &aux2); + } + return assign(tp, &aux2, ret); } return ret;