shithub: mc

Download patch

ref: 6ea8a68ea95f580877d171bdd4c4ab581a5f0d76
parent: 7fdee7419531c20ed3fe8c71634ff077f094a518
author: Ori Bernstein <[email protected]>
date: Thu Oct 3 06:49:56 EDT 2013

Do a correct subreg check.

--- a/6/asm.h
+++ b/6/asm.h
@@ -214,6 +214,7 @@
 extern Mode regmodes[];  /* mode table */
 extern size_t modesize[]; /* mode size table */
 void regalloc(Isel *s);
+Rclass rclass(Loc *l);
 
 
 /* useful functions */
--- a/6/insns.def
+++ b/6/insns.def
@@ -62,6 +62,7 @@
 Insn(Icvttsi2sd, "\tcvttsd2si%2t %x,%r\n",      Use(.l={1}),                    Def(.l={2}))
 Insn(Ifdiv,      "\tdiv%t %x,%r\n",             Use(.l={1},.r={Reax,Redx}),     Def(.r={Reax,Redx}))
 Insn(Ifmul,      "\tmul%t %x,%r\n",             Use(.l={1,2}),                  Def(.l={2}))
+Insn(Ifmov,      "\tmov%t %x,%x\n",             Use(.l={1,2}),                  Def(.l={2}))
 Insn(Icomi,      "\tcomi%t %x,%r\n",            Use(.l={1,2}),                  Def())
 
 /* branch instructions */
--- a/6/isel.c
+++ b/6/isel.c
@@ -509,6 +509,8 @@
             r = inr(s, r);
             if (floatnode(args[0])) {
                 sz = size(args[0]);
+                a = NULL;
+                b = NULL;
                 if (sz == 4) {
                     a = locreg(ModeD);
                     b = loclit(1 << (8*sz-1), ModeD);
@@ -728,6 +730,11 @@
     }
 }
 
+int subreg(Loc *a, Loc *b)
+{
+    return rclass(a) == rclass(b) && a->mode != b->mode;
+}
+
 void iprintf(FILE *fd, Insn *insn)
 {
     char *p;
@@ -754,7 +761,7 @@
                 break;
             /* if one reg is a subreg of another, we can just use the right
              * mode to move between them. */
-            if (insn->args[0]->mode != insn->args[1]->mode)
+            if (subreg(insn->args[0], insn->args[1]))
                 insn->args[0] = coreg(insn->args[0]->reg.colour, insn->args[1]->mode);
             /* moving a reg to itself is dumb. */
      //       if (insn->args[0]->reg.colour == insn->args[1]->reg.colour)
--- a/6/ra.c
+++ b/6/ra.c
@@ -102,7 +102,7 @@
     [Classflt] = 16,
 };
 
-static Rclass rclass(Loc *l)
+Rclass rclass(Loc *l)
 {
     switch (l->mode) {
         case ModeNone:  return Classbad;