shithub: scc

Download patch

ref: 05ade8e9661b399ac67cb352a6f4d4e70b426d47
parent: a589d0219533d196d7c80539629b3e47e97d4a9d
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Nov 3 01:43:59 EDT 2021

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.

--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -585,9 +585,14 @@
 				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;