shithub: riscv

Download patch

ref: 391198888a71649067d10862db1f1afed2b69c90
parent: 7b8f4b25be690482793b8bc1be84e8fad4b5492e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Apr 28 18:53:50 EDT 2014

8c, 6c: fix peephole bug for eleminating CMPL $0,R after shift

the shift instructions does not change the zero flag
when the shift count is 0, so we cannot remove the
compare instruction in this case.

this fixes oggdec under 386.

--- a/sys/src/cmd/6c/peep.c
+++ b/sys/src/cmd/6c/peep.c
@@ -210,6 +210,13 @@
 				break;
 			p1 = r1->prog;
 			switch(p1->as){
+			case ASHLQ:
+			case ASHRQ:
+			case ASALQ:
+			case ASARQ:
+				/* shift doesnt affect ZF when shift count is zero */
+				if(p1->from.type != D_CONST || p1->from.offset == 0)
+					break;
 			case AANDQ:
 			case AORQ:
 			case AXORQ:
@@ -218,10 +225,6 @@
 			case AADCQ:
 			case ASUBQ:
 			case ASBBQ:
-			case ASHLQ:
-			case ASHRQ:
-			case ASALQ:
-			case ASARQ:
 			case AINCQ:
 			case ADECQ:
 				if(p->as != ACMPQ)
@@ -234,12 +237,17 @@
 			case AADCL:
 			case ASUBL:
 			case ASBBL:
+			case AINCL:
+			case ADECL:
+				excise(r);
+				break;
 			case ASHLL:
 			case ASHRL:
 			case ASALL:
 			case ASARL:
-			case AINCL:
-			case ADECL:
+				/* shift doesnt affect ZF when shift count is zero */
+				if(p1->from.type != D_CONST || p1->from.offset == 0)
+					break;
 				excise(r);
 			}
 			break;
--- a/sys/src/cmd/8c/peep.c
+++ b/sys/src/cmd/8c/peep.c
@@ -150,6 +150,13 @@
 				break;
 			p1 = r1->prog;
 			switch(p1->as){
+			case ASALL:
+			case ASARL:
+			case ASHLL:
+			case ASHRL:
+				/* shift doesnt affect ZF when shift count is zero */
+				if(p1->from.type != D_CONST || p1->from.offset == 0)
+					break;
 			case AANDL:
 			case AORL:
 			case AXORL:
@@ -158,10 +165,6 @@
 			case AADCL:
 			case ASUBL:
 			case ASBBL:
-			case ASHLL:
-			case ASHRL:
-			case ASALL:
-			case ASARL:
 			case AINCL:
 			case ADECL:
 				excise(r);