shithub: riscv

Download patch

ref: 1ce4662c613bd407ef91ed8a782d7ed25bbc9d9b
parent: 2810cc5d0c01b06e678b50995edb724c739b8eed
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jul 4 19:53:01 EDT 2023

7c: dont replace SXTW instruction following MOVW $const, r

All the MOVW instructions sign extend to full
register size, but "MOVW $cosnt, R" is the exception,
being equivalent to "MOVWU $const, R" (for historical
reasons?).

This fixes hjfs regression.

--- a/sys/src/cmd/7c/peep.c
+++ b/sys/src/cmd/7c/peep.c
@@ -252,11 +252,14 @@
 			if((r1 = findset(r, &p->from)) != R){
 				p1 = r1->prog;
 				switch(p1->as){
+				case AMOVW:
+					/* MOVW $const,r; does not sign extend */
+					if(p1->from.type == D_CONST && (p1->from.offset & 0x80000000) != 0)
+						break;
 				case AMOVB:
-				case AMOVBU:
 				case AMOVH:
+				case AMOVBU:
 				case AMOVHU:
-				case AMOVW:
 					if(p1->to.type == p->from.type && p1->to.reg == p->from.reg)
 						p->as = AMOVW;
 					break;