fix code generation of CMP to use registers properly. also fix
one case of uninitialized memory and some output.

R=rsc
APPROVED=rsc
DELTA=73  (43 added, 1 deleted, 29 changed)
OCL=34743
CL=34772
diff --git a/src/cmd/5g/cgen.c b/src/cmd/5g/cgen.c
index 0efeb51..d6c55a0 100644
--- a/src/cmd/5g/cgen.c
+++ b/src/cmd/5g/cgen.c
@@ -42,7 +42,7 @@
 cgen(Node *n, Node *res)
 {
 	Node *nl, *nr, *r;
-	Node n1, n2;
+	Node n1, n2, n3;
 	int a, w;
 	Prog *p1, *p2, *p3;
 	Addr addr;
@@ -132,7 +132,14 @@
 	}
 
 	if(n->addable) {
-		gmove(n, res);
+		if (n->op == OREGISTER || is64(n->type) || is64(res->type)) {
+			gmove(n, res);
+		} else {
+			regalloc(&n1, n->type, N);
+			gmove(n, &n1);
+			cgen(&n1, res);
+			regfree(&n1);
+		}
 		goto ret;
 	}
 
@@ -151,7 +158,6 @@
 
 	// 64-bit ops are hard on 32-bit machine.
 	if(is64(n->type) || is64(res->type) || n->left != N && is64(n->left->type)) {
-		print("64 bit op %O\n", n->op);
 		switch(n->op) {
 		// math goes to cgen64.
 		case OMINUS:
@@ -279,8 +285,10 @@
 			cgen(nl, &n1);
 
 			nodconst(&n2, types[tptr], 0);
+			regalloc(&n3, n2.type, N);
 			p1 = gins(optoas(OCMP, types[tptr]), &n1, N);
-			raddr(&n2, p1);
+			raddr(&n3, p1);
+			regfree(&n3);
 			p1 = gbranch(optoas(OEQ, types[tptr]), T);
 
 			n2 = n1;
@@ -396,7 +404,7 @@
 agen(Node *n, Node *res)
 {
 	Node *nl, *nr;
-	Node n1, n2, n3, tmp;
+	Node n1, n2, n3, n4, tmp;
 	Prog *p1;
 	uint32 w;
 	uint64 v;
@@ -492,7 +500,11 @@
 					n1.type = types[tptr];
 					n1.xoffset = Array_nel;
 					nodconst(&n2, types[TUINT32], v);
-					gins(optoas(OCMP, types[TUINT32]), &n1, &n2);
+					regalloc(&n4, n2.type, N);
+					cgen(&n2, &n4);
+					p1 = gins(optoas(OCMP, types[TUINT32]), &n1, N);
+					raddr(&n4, p1);
+					regfree(&n4);
 					p1 = gbranch(optoas(OGT, types[TUINT32]), T);
 					ginscall(throwindex, 0);
 					patch(p1, pc);
@@ -536,9 +548,14 @@
 				n1.op = OINDREG;
 				n1.type = types[tptr];
 				n1.xoffset = Array_nel;
-			} else
+			} else {
 				nodconst(&n1, types[TUINT32], nl->type->bound);
-			gins(optoas(OCMP, types[TUINT32]), &n2, &n1);
+			}
+			regalloc(&n4, n1.type, N);
+			cgen(&n1, &n4);
+			p1 = gins(optoas(OCMP, types[TUINT32]), &n2, N);
+			raddr(&n4, p1);
+			regfree(&n4);
 			p1 = gbranch(optoas(OLT, types[TUINT32]), T);
 			ginscall(throwindex, 0);
 			patch(p1, pc);
@@ -702,7 +719,7 @@
 		cgen(&n1, &n2);
 		cgen(n, &n3);
 		p1 = gins(optoas(OCMP, n->type), &n2, N);
-		p1->reg = n3.val.u.reg;
+		raddr(&n3, p1);
 		a = ABNE;
 		if(!true)
 			a = ABEQ;
@@ -783,13 +800,17 @@
 			}
 			a = optoas(a, types[tptr]);
 			regalloc(&n1, types[tptr], N);
+			regalloc(&n3, types[tptr], N);
 			agen(nl, &n1);
 			n2 = n1;
 			n2.op = OINDREG;
 			n2.xoffset = Array_array;
 			nodconst(&tmp, types[tptr], 0);
-			gins(optoas(OCMP, types[tptr]), &n2, &tmp);
+			cgen(&tmp, &n3);
+			p1 = gins(optoas(OCMP, types[tptr]), &n2, N);
+			raddr(&n3, p1);
 			patch(gbranch(a, types[tptr]), to);
+			regfree(&n3);
 			regfree(&n1);
 			break;
 		}
@@ -802,14 +823,18 @@
 			}
 			a = optoas(a, types[tptr]);
 			regalloc(&n1, types[tptr], N);
+			regalloc(&n3, types[tptr], N);
 			agen(nl, &n1);
 			n2 = n1;
 			n2.op = OINDREG;
 			n2.xoffset = 0;
 			nodconst(&tmp, types[tptr], 0);
-			gins(optoas(OCMP, types[tptr]), &n2, &tmp);
+			cgen(&tmp, &n3);
+			p1 = gins(optoas(OCMP, types[tptr]), &n2, N);
+			raddr(&n3, p1);
 			patch(gbranch(a, types[tptr]), to);
 			regfree(&n1);
+			regfree(&n3);
 			break;
 		}
 
@@ -826,10 +851,11 @@
 			regalloc(&n1, nl->type, N);
 			cgen(nl, &n1);
 
-			regalloc(&n2, nr->type, &n2);
+			regalloc(&n2, nr->type, N);
 			cgen(&tmp, &n2);
 
-			gins(optoas(OCMP, nr->type), &n1, &n2);
+			p1 = gins(optoas(OCMP, nr->type), &n1, N);
+			raddr(&n2, p1);
 			patch(gbranch(a, nr->type), to);
 
 			regfree(&n1);
@@ -969,7 +995,8 @@
 			p->to.offset = -4;
 			p->scond |= C_PBIT;
 
-			gins(ACMP, &src, &nend);
+			p = gins(ACMP, &src, N);
+			raddr(&nend, p);
 
 			patch(gbranch(ABNE, T), ploop);
 
@@ -994,7 +1021,8 @@
 			p->to.offset = 4;
 			p->scond |= C_PBIT;
 
-			gins(ACMP, &src, &nend);
+			p = gins(ACMP, &src, N);
+			raddr(&nend, p);
 
 			patch(gbranch(ABNE, T), ploop);
 
diff --git a/src/cmd/5g/ggen.c b/src/cmd/5g/ggen.c
index 46c335f..00b44b0 100644
--- a/src/cmd/5g/ggen.c
+++ b/src/cmd/5g/ggen.c
@@ -464,7 +464,8 @@
 		p->scond |= C_PBIT;
 		pl = p;
 
-		gins(ACMP, &dst, &end);
+		p = gins(ACMP, &dst, N);
+		raddr(&end, p);
 		patch(gbranch(ABNE, T), pl);
 
 		regfree(&end);
diff --git a/src/cmd/5g/gsubr.c b/src/cmd/5g/gsubr.c
index 4458256..37e9db1 100644
--- a/src/cmd/5g/gsubr.c
+++ b/src/cmd/5g/gsubr.c
@@ -957,15 +957,16 @@
 		a->offset = n->xoffset;
 		break;
 
-//	case OPARAM:
-//		// n->left is PHEAP ONAME for stack parameter.
-//		// compute address of actual parameter on stack.
-//		a->etype = simtype[n->left->type->etype];
-//		a->width = n->left->type->width;
-//		a->offset = n->xoffset;
-//		a->sym = n->left->sym;
-//		a->type = D_PARAM;
-//		break;
+	case OPARAM:
+		// n->left is PHEAP ONAME for stack parameter.
+		// compute address of actual parameter on stack.
+		a->etype = simtype[n->left->type->etype];
+		a->width = n->left->type->width;
+		a->offset = n->xoffset;
+		a->sym = n->left->sym;
+		a->type = D_OREG;
+		a->name = D_PARAM;
+		break;
 
 	case ONAME:
 		a->etype = 0;
@@ -1606,7 +1607,11 @@
 			if(o & OPtrto)
 				nodconst(&n2, types[TUINT32], l->type->type->bound);
 		}
-		gins(optoas(OCMP, types[TUINT32]), reg1, &n2);
+		regalloc(&n3, n2.type, N);
+		cgen(&n2, &n3);
+		p1 = gins(optoas(OCMP, types[TUINT32]), reg1, N);
+		raddr(&n3, p1);
+		regfree(&n3);
 		p1 = gbranch(optoas(OLT, types[TUINT32]), T);
 		ginscall(throwindex, 0);
 		patch(p1, pc);
@@ -1648,7 +1653,11 @@
 			n1.type = types[tptr];
 			n1.xoffset = Array_nel;
 			nodconst(&n2, types[TUINT32], v);
-			gins(optoas(OCMP, types[TUINT32]), &n1, &n2);
+			regalloc(&n3, types[TUINT32], N);
+			cgen(&n2, &n3);
+			p1 = gins(optoas(OCMP, types[TUINT32]), &n1, N);
+			raddr(&n3, p1);
+			regfree(&n3);
 			p1 = gbranch(optoas(OGT, types[TUINT32]), T);
 			ginscall(throwindex, 0);
 			patch(p1, pc);
diff --git a/src/cmd/5g/list.c b/src/cmd/5g/list.c
index c408fab..01a0bc5 100644
--- a/src/cmd/5g/list.c
+++ b/src/cmd/5g/list.c
@@ -60,9 +60,10 @@
 		break;
 
 	case ADATA:
-		sconsize = p->reg;
+	case AINIT:
+	case ADYNT:
 		snprint(str, sizeof(str), "%.4ld (%L) %-7A %D/%d,%D",
-			p->loc, p->lineno, p->as, &p->from, sconsize, &p->to);
+			p->loc, p->lineno, p->as, &p->from, p->reg, &p->to);
 		break;
 
 	case ATEXT:
@@ -99,7 +100,10 @@
 		break;
 
 	case D_BRANCH:
-		snprint(str, sizeof(str), "%d", a->branch->loc);
+		if(a->sym != S)
+			sprint(str, "%s+%d(APC)", a->sym->name, a->offset);
+		else
+			sprint(str, "%d(APC)", a->offset);
 		break;
 
 	case D_CONST: