git: 9front

Download patch

ref: f4c733880aee7a1224d3d2ebb3bd2c6d8859cbd1
parent: e6b1fd0485fe24bd965fd811ccac6131c9b37a95
author: Arusekk <floss@arusekk.pl>
date: Tue Sep 23 19:43:10 EDT 2025

c: use hint for register pair

Avoid register allocation leak on 32-bit to 64-bit casts,
by re-using the target register.

This change allows 5c (and hopefully the other ones) to work with more
complex expressions without running out of fixed registers.
The expected byproduct is a minimal reduction in the number of code
size and therefore speed.

A generic stack spill could be better, but this suffices to compile some
programs that make heavy use of 64-bit arithmetic.

--- a/sys/src/cmd/5c/cgen.c
+++ b/sys/src/cmd/5c/cgen.c
@@ -954,7 +954,7 @@
 					regfree(&nod0);
 					regfree(&nod1);
 				} else {
-					regalloc(&nod0, l, Z);
+					regalloc(&nod0, l, nn);
 					cgen(l, &nod0);
 					cgen(nod0.left, nn);
 					regfree(&nod0);
--- a/sys/src/cmd/5c/txt.c
+++ b/sys/src/cmd/5c/txt.c
@@ -338,7 +338,7 @@
 			regalloc(n->left, &regnode, o->left);
 			regalloc(n->right, &regnode, o->right);
 		} else {
-			regalloc(n->left, &regnode, Z);
+			regalloc(n->left, &regnode, o);
 			regalloc(n->right, &regnode, Z);
 		}
 		if(n->left->reg > n->right->reg){
--- a/sys/src/cmd/8c/txt.c
+++ b/sys/src/cmd/8c/txt.c
@@ -331,7 +331,7 @@
 			regalloc(n->left, &regnode, o->left);
 			regalloc(n->right, &regnode, o->right);
 		} else {
-			regalloc(n->left, &regnode, Z);
+			regalloc(n->left, &regnode, o);
 			regalloc(n->right, &regnode, Z);
 		}
 		n->right->type = types[TULONG];
--- a/sys/src/cmd/qc/txt.c
+++ b/sys/src/cmd/qc/txt.c
@@ -336,7 +336,7 @@
 			regalloc(n->right, &regnode, o->right);
 		} else {
 			regalloc(n->left, &regnode, Z);
-			regalloc(n->right, &regnode, Z);
+			regalloc(n->right, &regnode, o);
 		}
 		n->right->type = types[TULONG];
 		if(tn->type->etype == TUVLONG)
--