git: 9front

Download patch

ref: 8881d0a468ff6cf8e230dd03d66d29c2be08f663
parent: 02dc6c44a85722d2ee7e1fe788f404fc286a3f50
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Sep 24 16:45:16 EDT 2014

6c/8c: eleminate moves by swaping source and destination operands in peephole pass

--- a/sys/src/cmd/6c/peep.c
+++ b/sys/src/cmd/6c/peep.c
@@ -407,6 +407,30 @@
 		case AMOVQL:
 			return 0;
 
+		case AORL:
+		case AORQ:
+		case AANDL:
+		case AANDQ:
+		case AXORL:
+		case AXORQ:
+		case AADDL:
+		case AADDQ:
+		case AADCL:
+		case AADCQ:
+			/*
+			 * can swap when:
+			 *  ADD R2, R1
+			 *  MOV R1, R2
+			 * convert to:
+			 *  ADD R1, R2
+			 *  MOV R2, R1	/ no use for R1
+			 */
+			if(p->to.type == v1->type && p->from.type == v2->type){
+				copysub(&p->from, v2, v1, 1);
+				goto gotit;
+			}
+			break;
+
 		case AMOVL:
 		case AMOVQ:
 			if(p->to.type == v1->type)
--- a/sys/src/cmd/8c/peep.c
+++ b/sys/src/cmd/8c/peep.c
@@ -315,6 +315,25 @@
 		case AFSTSW:
 			return 0;
 
+		case AORL:
+		case AANDL:
+		case AXORL:
+		case AADDL:
+		case AADCL:
+			/*
+			 * can swap when:
+			 *  ADD R2, R1
+			 *  MOV R1, R2
+			 * convert to:
+			 *  ADD R1, R2
+			 *  MOV R2, R1	/ no use for R1
+			 */
+			if(p->to.type == v1->type && p->from.type == v2->type){
+				copysub(&p->from, v2, v1, 1);
+				goto gotit;
+			}
+			break;
+
 		case AMOVL:
 			if(p->to.type == v1->type)
 				goto gotit;
--