bug fix in value_number.m

Fergus Henderson fjh at cs.mu.oz.au
Fri Apr 18 20:46:21 AEST 1997


Zoltan, can you please review this one?

--------------------

Fix a bug that caused value numbering to get an internal error
when compiling library/parser.m at -O5 in a non-gc grade.

compiler/value_number.m:
	Fix a bug: it was using peephole optimization to delete an inserted
	goto to the next label, in order to maintain an invariant,
	but peephole had been changed (that optimization had been moved
	from peephole to jumpopt).  I changed it to instead delete the
	goto manually.

Index: value_number.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/value_number.m,v
retrieving revision 1.80
diff -u -r1.80 value_number.m
--- value_number.m	1997/01/15 01:10:45	1.80
+++ value_number.m	1997/04/18 10:39:15
@@ -536,17 +536,33 @@
 			{ Instrs = [Instr0 | Instrs1] }
 		;
 			vn_debug__divide_msg(Instr0),
+			%
+			% we need to append a `goto' instruction at the
+			% end of the fragment so that optimize_fragment
+			% can know what is live at the end.
+			%
 			{ GotoInstr = goto(label(RestartLabel)) - "" },
 			{ list__reverse([GotoInstr | RevInstrs0],
 				FrontInstrs0) },
 			value_number__optimize_fragment(FrontInstrs0, LiveMap,
-				Params, [], LabelNo0, _, FrontInstrs),
+				Params, [], LabelNo0, _, FrontInstrs1),
 			value_number__optimize_fragment(Instrs0, LiveMap,
 				Params, [], LabelNo0, _, BackInstrs),
+			%
+			% we need to get rid of the introduced goto,
+			% which should still be at the end of FrontInstrs1,
+			% otherwise we would violate the invariant that
+			% labels in the middle of a block are not targets
+			% of branches.
+			%
+			{ list__reverse(FrontInstrs1, RevInstrs1) },
+			{ RevInstrs1 = [GotoInstr | RevInstrs2] ->
+				list__reverse(RevInstrs2, FrontInstrs)
+			;
+				error("value_number__try_again: lost goto")
+			},
 			{ list__append(FrontInstrs, [Instr0 | BackInstrs],
-				Instrs1) },
-			% to get rid of the introduced goto
-			{ peephole__optimize(Instrs1, Instrs, _) }
+				Instrs) }
 		)
 	;
 		{ RevInstrs1 = [Instr0 | RevInstrs0] },

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list