summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-11 19:49:52 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit7ce4d334e54433f7e67d91baa9edb25adb26975b (patch)
tree55e3544fa1ddd75b6436760ccbd90c24eda8dd44
parentd37db3970f06e46d1ea9b55084e065e799b09576 (diff)
downloadroux-7ce4d334e54433f7e67d91baa9edb25adb26975b.tar.gz
add a small size optimization to emit
-rw-r--r--lisc/emit.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index d72ea79..80df768 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -141,6 +141,7 @@ eins(Ins i, Fn *fn, FILE *f)
 		[OStoreb - OStorel] = "b",
 	};
 	int r;
+	int64_t val;
 
 	switch (i.op) {
 	case OAdd:
@@ -159,6 +160,14 @@ eins(Ins i, Fn *fn, FILE *f)
 		eop(otoa[i.op], i.arg[1], i.to, fn, f);
 		break;
 	case OCopy:
+		if (i.to.val < EAX && rtype(i.arg[0]) == RCon) {
+			val = fn->con[i.arg[0].val].val;
+			if (0 <= val && val <= UINT32_MAX) {
+				fprintf(f, "\tmov $%"PRId64", %%%s\n",
+					val, rsub[i.to.val][SWord]);
+				break;
+			}
+		}
 		if (!req(i.arg[0], i.to))
 			eop("mov", i.arg[0], i.to, fn, f);
 		break;