summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--amd64/emit.c10
-rw-r--r--amd64/isel.c2
2 files changed, 12 insertions, 0 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index cd485bb..4d4d3be 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -405,6 +405,16 @@ emitins(Ins i, Fn *fn, FILE *f)
 			break;
 		}
 		goto Table;
+	case Odiv:
+		/* adjust the instruction when the conversion to
+		 * a 2-address division is impossible */
+		if (req(i.to, i.arg[1])) {
+			i.arg[1] = TMP(XMM0+15);
+			emitf("mov%k %=, %1", &i, fn, f);
+			emitf("mov%k %0, %=", &i, fn, f);
+			i.arg[0] = i.to;
+		}
+		goto Table;
 	case Ocopy:
 		/* make sure we don't emit useless copies,
 		 * also, we can use a trick to load 64-bits
diff --git a/amd64/isel.c b/amd64/isel.c
index 39fc9e8..180439b 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -200,6 +200,8 @@ sel(Ins i, ANum *an, Fn *fn)
 	case Orem:
 	case Oudiv:
 	case Ourem:
+		if (KBASE(k) == 1)
+			goto Emit;
 		if (i.op == Odiv || i.op == Oudiv)
 			r0 = TMP(RAX), r1 = TMP(RDX);
 		else