summary refs log tree commit diff
path: root/lisc/isel.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-05 16:13:18 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:30 -0400
commit078522cf5d5b7adbe56fb1300e47f642616354d5 (patch)
treee41677dd1e65b21bebc2d25f7a1b5a069b9f7de8 /lisc/isel.c
parentdba612623fcd5c58569ef8ac32085e8aacaef435 (diff)
downloadroux-078522cf5d5b7adbe56fb1300e47f642616354d5.tar.gz
use a temporary for constant comparisons
Diffstat (limited to 'lisc/isel.c')
-rw-r--r--lisc/isel.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/lisc/isel.c b/lisc/isel.c
index faea3b5..ea4aa01 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -86,15 +86,25 @@ sel(Ins i, Fn *fn)
 		break;
 	default:
 		if (OCmp <= i.op && i.op <= OCmp1) {
+			r0 = i.arg[0];
 			c = i.op - OCmp;
 			if (rtype(i.arg[0]) == RCon) {
-				r0 = i.arg[0];
-				i.arg[0] = i.arg[1];
-				i.arg[1] = r0;
-				c = CNEG(c);
+				if (rtype(i.arg[1]) == RCon) {
+					/* todo, use the constant
+					 * size to dimension the
+					 * constant */
+					t = newtmp(TWord, fn);
+					r0 = TMP(t);
+				} else {
+					r0 = i.arg[1];
+					i.arg[1] = i.arg[0];
+					c = CNEG(c);
+				}
 			}
 			emit(OXSet+c, i.to, R, R);
-			emit(OXCmp, R, i.arg[1], i.arg[0]);
+			emit(OXCmp, R, i.arg[1], r0);
+			if (!req(r0, i.arg[0]))
+				emit(OCopy, r0, i.arg[0], R);
 			break;
 		}
 		diag("isel: non-exhaustive implementation");