for review: fix a bug in value numbering reported by Simon
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Aug 26 15:06:50 AEST 1998
Fix a bug in value numbering reported by Simon.
compiler/vn_block.m:
Restore a previously commented block of code, whose job is to force
the flushing of any stack slot that holds the saved value of a nondet
control register or stack slot. The rationale for this code used
to be the handling of cuts in nondet code; now it is the handling
of hijackings.
tests/hard_coded.{m,exp}:
A cut-down and inlined version of Simon's test case, which fails
without the change to vn_block and succeeds with it.
tests/Mmakefile:
Enable the new test case, and require that it be compiled with
value numbering.
Zoltan.
Index: compiler/vn_block.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_block.m,v
retrieving revision 1.56
diff -u -u -r1.56 vn_block.m
--- vn_block.m 1998/07/29 08:53:49 1.56
+++ vn_block.m 1998/08/25 05:12:52
@@ -203,27 +203,25 @@
vn_util__rval_to_vn(Rval, Vn, VnTables0, VnTables1),
vn_util__lval_to_vnlval(Lval, Vnlval, VnTables1, VnTables2),
vn_table__set_desired_value(Vnlval, Vn, VnTables2, VnTables),
- vn_util__find_specials(Vnlval, Specials),
-% vn_util__find_specials(Vnlval, LeftSpecials),
-% (
-% % Assignments of this form occur in the setup for commit.
-% % We must record the left hand side (which will be a stackvar)
-% % as a must flush location, because liveness will not force
-% % it to be flushed. The reason for this is that livemap.m
-% % may be confused by an incr_sp and assignment to a similarly
-% % numbered stackvar in later code into thinking that this
-% % assignment is redundant.
-% Rval = lval(SubLval),
-% ( SubLval = curfr
-% ; SubLval = maxfr
-% ; SubLval = redoip(_)
-% ; SubLval = redofr(_)
-% )
-% ->
-% Specials = [Vnlval | LeftSpecials]
-% ;
-% Specials = LeftSpecials
-% ),
+ vn_util__find_specials(Vnlval, LeftSpecials),
+ (
+ % Assignments of this form occur in hijacking.
+ % We must record the left hand side (which will be a stackvar
+ % or framevar) as a must flush location, because liveness will
+ % not force it to be flushed. The reason for this is that
+ % we do not properly include temporary slots (such as those
+ % used by hijacking) in livevals annotations.
+ Rval = lval(SubLval),
+ ( SubLval = curfr
+ ; SubLval = maxfr
+ ; SubLval = redoip(_)
+ ; SubLval = redofr(_)
+ )
+ ->
+ Specials = [Vnlval | LeftSpecials]
+ ;
+ Specials = LeftSpecials
+ ),
set__insert_list(Liveset0, Specials, Liveset).
vn_block__handle_instr(call(Proc, Return, Info, CallModel),
Livemap, Params, VnTables0, VnTables, Liveset0, Liveset,
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.38
diff -u -u -r1.38 Mmakefile
--- Mmakefile 1998/07/29 08:56:59 1.38
+++ Mmakefile 1998/08/25 08:50:11
@@ -58,6 +58,7 @@
nested3 \
no_fully_strict \
no_inline \
+ nondet_ctrl_vn \
nullary_ho_func \
parent \
parent2 \
@@ -88,7 +89,7 @@
# The following is required to make the test cases
# nested, nested2, and nested3
-# work reliabily with parallel makes -- without this they occaisionally fail.
+# work reliabily with parallel makes -- without this they occasionally fail.
RM_C = :
#-----------------------------------------------------------------------------#
@@ -100,6 +101,7 @@
MCFLAGS-ho_order = --optimize-higher-order
MCFLAGS-ho_order2 = --optimize-higher-order
MCFLAGS-no_fully_strict = --no-fully-strict
+MCFLAGS-nondet_ctrl_vn = --optimize-value-number
MCFLAGS-rnd = -O6
# In grade `none' with options `-O1 --opt-space' on kryten
Index: tests/hard_coded/nondet_ctrl_vn.exp
===================================================================
RCS file: nondet_ctrl_vn.exp
diff -N nondet_ctrl_vn.exp
--- /dev/null Wed May 28 10:49:58 1997
+++ nondet_ctrl_vn.exp Tue Aug 25 20:51:00 1998
@@ -0,0 +1 @@
+test failed: OK.
Index: tests/hard_coded/nondet_ctrl_vn.m
===================================================================
RCS file: nondet_ctrl_vn.m
diff -N nondet_ctrl_vn.m
--- /dev/null Wed May 28 10:49:58 1997
+++ nondet_ctrl_vn.m Tue Aug 25 18:47:42 1998
@@ -0,0 +1,41 @@
+% This is a regression test. The 1998 August 24 version of the compiler
+% generated incorrect code for this module, the bug being that the value
+% numbering pass did not properly flush stack slots that hold the old values
+% of hijacked nondet control slots.
+%
+% This is a cut-down version of cut_test.m
+
+:- module nondet_ctrl_vn.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module int.
+
+main -->
+ ( { middle(100) } ->
+ io__write_string("test succeeded: BUG.\n")
+ ;
+ io__write_string("test failed: OK.\n")
+ ).
+
+:- pragma no_inline(middle/1).
+:- pred middle(int::in) is semidet.
+
+middle(A0) :-
+ (
+ A is A0 + 10
+ ;
+ A is A0 + 20
+ ),
+ A > 200,
+ (
+ B is A
+ ;
+ B is A * 2
+ ).
More information about the developers
mailing list