(0000098)
|
juliensf
|
2008-04-04 17:43
(Last edited: 2008-04-04 17:44) |
|
The reason that the compiler no longer performs LCMC optimisation is a change in the
behaviour of common structure optimisation:
Compiling with: -O2 --optimize-constructor-last-call --nolining --no-common-struct
gives me the following at stage 135 (which is the last pass that does something meaningful
before the LCMC pass) for the predicate to_list_2.
bag_to_list.to_list_2(TypeInfo_for_T, HeadVar__1, HeadVar__2) :-
( % cannot_fail switch on `HeadVar__1'
% HeadVar__1 has functor list.[]/0
HeadVar__2 = list.[]
;
% HeadVar__1 has functor list.[|]/2
HeadVar__1 = list.[V_9 | Xs],
V_9 = pair.(X - Int),
(if
V_10 = 0,
int.(Int =< V_10)
then
bag_to_list.to_list_2(TypeInfo_for_T, Xs, HeadVar__2)
else
V_11 = 1,
NewInt = int.(Int - V_11),
V_13 = pair.(X - NewInt),
V_12 = list.[V_13 | Xs],
bag_to_list.to_list_2(TypeInfo_for_T, V_12, Out0),
HeadVar__2 = list.[X | Out0]
)
).
Enabling common structure optimisation gives the following:
bag_to_list.to_list_2(TypeInfo_for_T, HeadVar__1, HeadVar__2) :-
( % cannot_fail switch on `HeadVar__1'
% HeadVar__1 has functor list.[]/0
HeadVar__2 = list.[]
;
% HeadVar__1 has functor list.[|]/2
HeadVar__1 = list.[V_9 | Xs],
V_9 = pair.(X - Int),
(if
V_10 = 0,
int.(Int =< V_10)
then
bag_to_list.to_list_2(TypeInfo_for_T, Xs, Out)
else
V_11 = 1,
NewInt = int.(Int - V_11),
V_13 = pair.(X - NewInt),
V_12 = list.[V_13 | Xs],
bag_to_list.to_list_2(TypeInfo_for_T, V_12, Out0),
Out = list.[X | Out0]
),
HeadVar__2 = Out
).
The unification HeadVar__2 = Out is introduced in stage 65 by common structure optimisation
and it inhibits LCMC. Compiling with --no-common-struct causes the program to exhibit
the original buggy behaviour reported by Peter Wang.
Since there is no advantage gained by adding the new assignment unification and given
that it inhibits other optimisations this behaviour from --common-struct is also a bug.
|
|