Browse Source

reenable and fix a bug in memopt

While a minimal dead store elimination is not
implemented, the generated code looks quite a
bit better with them enabled.  It also is quite
cheap.
Quentin Carbonneaux 8 years ago
parent
commit
f3301026fa
2 changed files with 5 additions and 2 deletions
  1. 1 1
      main.c
  2. 4 1
      mem.c

+ 1 - 1
main.c

@@ -50,7 +50,7 @@ func(Fn *fn)
 	fillrpo(fn);
 	fillrpo(fn);
 	fillpreds(fn);
 	fillpreds(fn);
 	filluse(fn);
 	filluse(fn);
-	/* memopt(fn); */
+	memopt(fn);
 	ssa(fn);
 	ssa(fn);
 	filluse(fn);
 	filluse(fn);
 	ssacheck(fn);
 	ssacheck(fn);

+ 4 - 1
mem.c

@@ -86,15 +86,18 @@ memopt(Fn *fn)
 				/* try to turn loads into copies so we
 				/* try to turn loads into copies so we
 				 * can eliminate them later */
 				 * can eliminate them later */
 				switch(l->op) {
 				switch(l->op) {
-				case Oload:
 				case Oloadsw:
 				case Oloadsw:
 				case Oloaduw:
 				case Oloaduw:
+					if (k == Kl)
+						goto Extend;
+				case Oload:
 					if (KBASE(k) != KBASE(l->cls))
 					if (KBASE(k) != KBASE(l->cls))
 						l->op = Ocast;
 						l->op = Ocast;
 					else
 					else
 						l->op = Ocopy;
 						l->op = Ocopy;
 					break;
 					break;
 				default:
 				default:
+				Extend:
 					l->op = Oextsb + (l->op - Oloadsb);
 					l->op = Oextsb + (l->op - Oloadsb);
 					break;
 					break;
 				}
 				}