summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--all.h2
-rw-r--r--amd64/isel.c24
-rwxr-xr-xtools/test.sh3
3 files changed, 20 insertions, 9 deletions
diff --git a/all.h b/all.h
index 8cbec63..56c0ef9 100644
--- a/all.h
+++ b/all.h
@@ -86,7 +86,7 @@ enum {
 #define TMP(x)   (Ref){RTmp, x}
 #define CON(x)   (Ref){RCon, x}
 #define CON_Z    CON(0)          /* reserved zero constant */
-#define SLOT(x)  (Ref){RSlot, x}
+#define SLOT(x)  (Ref){RSlot, (x)&0x1fffffff}
 #define TYPE(x)  (Ref){RType, x}
 #define CALL(x)  (Ref){RCall, x}
 #define MEM(x)   (Ref){RMem, x}
diff --git a/amd64/isel.c b/amd64/isel.c
index 1623b9b..0dbaad3 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -59,14 +59,16 @@ rslot(Ref r, Fn *fn)
 }
 
 static void
-fixarg(Ref *r, int k, int cpy, Fn *fn)
+fixarg(Ref *r, int k, int op, Fn *fn)
 {
 	Addr a, *m;
 	Ref r0, r1;
-	int s, n;
+	int s, n, cpy, mem;
 
 	r1 = r0 = *r;
 	s = rslot(r0, fn);
+	cpy = op == Ocopy || op == -1;
+	mem = isstore(op) || isload(op) || op == Ocall;
 	if (KBASE(k) == 1 && rtype(r0) == RCon) {
 		/* load floating points from memory
 		 * slots, they can't be used as
@@ -97,6 +99,12 @@ fixarg(Ref *r, int k, int cpy, Fn *fn)
 		r1 = newtmp("isel", Kl, fn);
 		emit(Oaddr, Kl, r1, SLOT(s), R);
 	}
+	else if (!mem && rtype(r0) == RCon
+	&& fn->con[r0.val].type == CAddr) {
+		/* apple asm fix */
+		r1 = newtmp("isel", Kl, fn);
+		emit(Oaddr, Kl, r1, r0, R);
+	}
 	else if (rtype(r0) == RMem) {
 		/* apple asm fix */
 		m = &fn->mem[r0.val];
@@ -163,8 +171,8 @@ selcmp(Ref arg[2], int k, Fn *fn)
 		iarg[1] = newtmp("isel", k, fn);
 		emit(Ocopy, k, iarg[1], arg[0], R);
 	}
-	fixarg(&iarg[0], k, 0, fn);
-	fixarg(&iarg[1], k, 0, fn);
+	fixarg(&iarg[0], k, Oxcmp, fn);
+	fixarg(&iarg[1], k, Oxcmp, fn);
 	return swap;
 }
 
@@ -214,7 +222,7 @@ sel(Ins i, ANum *an, Fn *fn)
 			emit(Ocopy, k, TMP(RDX), CON_Z, R);
 		}
 		emit(Ocopy, k, TMP(RAX), i.arg[0], R);
-		fixarg(&curi->arg[0], k, 0, fn);
+		fixarg(&curi->arg[0], k, Ocopy, fn);
 		if (rtype(i.arg[1]) == RCon)
 			emit(Ocopy, k, r0, i.arg[1], R);
 		break;
@@ -269,8 +277,8 @@ sel(Ins i, ANum *an, Fn *fn)
 Emit:
 		emiti(i);
 		iarg = curi->arg; /* fixarg() can change curi */
-		fixarg(&iarg[0], argcls(&i, 0), 0, fn);
-		fixarg(&iarg[1], argcls(&i, 1), 0, fn);
+		fixarg(&iarg[0], argcls(&i, 0), i.op, fn);
+		fixarg(&iarg[1], argcls(&i, 1), i.op, fn);
 		break;
 	case Oalloc:
 	case Oalloc+1:
@@ -584,7 +592,7 @@ amd64_isel(Fn *fn)
 			for (p=(*sb)->phi; p; p=p->link) {
 				for (a=0; p->blk[a] != b; a++)
 					assert(a+1 < p->narg);
-				fixarg(&p->arg[a], p->cls, 1, fn);
+				fixarg(&p->arg[a], p->cls, -1, fn);
 			}
 		memset(ainfo, 0, n * sizeof ainfo[0]);
 		anumber(ainfo, b, fn->con);
diff --git a/tools/test.sh b/tools/test.sh
index 5430ccd..5c3f205 100755
--- a/tools/test.sh
+++ b/tools/test.sh
@@ -35,6 +35,9 @@ init() {
 		;;
 	"")
 		case `uname` in
+		*Darwin*)
+			cc="cc -Wl,-no_pie"
+			;;
 		*OpenBSD*)
 			cc="cc -nopie"
 			;;