Files
mercury/tests/hard_coded/constant_prop_2.m
Zoltan Somogyi 48e714d43f Make constant prop work with loop invariant opt.
compiler/common.m:
    The code that tries to optimize X = f(...) into X = Y if Y already
    contains f(...) used to insist on the X = f(...) construction unification
    being marked as a dynamic unification, i.e. one that constructs a term
    on the heap on each invocation. This was part of the fix of Mantis bug
    #493, which affected only the MLDS code generator, but for LLDS backend,
    in the presence of --loop-invariants, it prevented a constant propagation
    optimization that we had a test for (tests/hard_coded/constant_prop_2).
    So make both backends happy by insisting on construct_dynamically
    only for the MLDS backend.

compiler/simplify_info.m:
    Record for common.m whether the backend we are targeting pays
    any attention to whether a cell is construct_dynamically.

    Replace some bools with bespoke types, to eliminate the risk of confusion.

compiler/hlds_goal.m:
    For each construction unification marked construct_statically, record
    whether the term was "born static" by being created as a static term
    by a compiler pass, or whether it is a user-written unification that was
    "marked static" by mark_static_terms.m. Document the meaning of both.
    (I originally thought this distinction would be useful in the bug fix,
    but it turned out not to be.)

compiler/deep_profiling.m:
compiler/dep_par_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/polymorphism.m:
compiler/polymorphism_type_info.m:
    Record compiler-generated static terms as born static.

compiler/mark_static_terms.m:
    Mark discovered-to-be-static terms as marked static.

compiler/hlds_out_goal.m:
compiler/interval.m:
compiler/liveness.m:
compiler/loop_inv.m:
compiler/ml_unify_gen_construct.m:
compiler/quantification.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/simplify_goal.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_scope.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.versions.m:
compiler/unify_gen_construct.m:
compiler/var_locn.m:
    Conform to the changes above.

tests/hard_coded/constant_prop_loop_inv.{m,exp}:
    A new test case. It contains the part of the constant_prop_2 test case
    that used to fail in LLDS grades with --loop-invariants.

tests/hard_coded/Mercury.options:
    Specify --loop-invariants for the new test case, even if it is not
    specified for constant_prop_2.

tests/hard_coded/Mmakefile:
    Enable the new test case.

tests/hard_coded/constant_prop_2.m:
    Fix programming style.
2021-05-13 13:34:07 +10:00

74 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module constant_prop_2.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module float.
:- import_module int.
:- import_module string.
:- import_module uint.
main(!IO) :-
( if "abc" ++ "xyz" = "abcxyz" then
io.write_string("yes\n", !IO)
else
link_error(!IO)
),
( if 5 * 10000 + 4 * 1000 + 3 * 100 + 2 * 10 + 1 = 54321 then
io.write_string("yes\n", !IO)
else
link_error(!IO)
),
( if 4.0 * 1000.0 + 3.0 * 100.0 + 2.0 * 10.0 + 1.0 = 4321.0 then
io.write_string("yes\n", !IO)
else
link_error(!IO)
),
( if 8u * 1000u + 6u * 100u + 4u * 10u + 2u = 8642u then
io.write_string("yes\n", !IO)
else
link_error(!IO)
),
( if private_builtin.typed_unify(42, 42) then
io.write_string("yes\n", !IO)
else
link_error(!IO)
),
( if private_builtin.typed_unify(1, 2) then
link_error(!IO)
else
io.write_string("no\n", !IO)
),
( if private_builtin.typed_unify(43, X1) then
io.write_int(X1, !IO), io.nl(!IO)
else
link_error(!IO)
),
( if private_builtin.typed_unify(44, _ `with_type` string) then
link_error(!IO)
else
io.write_string("no\n", !IO)
),
( if dynamic_cast(45, X2) then
io.write_int(X2, !IO), io.nl(!IO)
else
link_error(!IO)
),
( if dynamic_cast(46, _ `with_type` string) then
link_error(!IO)
else
io.write_string("no\n", !IO)
).
% We should be able to optimize away all calls to this procedure
% at compile time, so we should not even emit a reference to it.
:- pred link_error(io::di, io::uo) is det.
:- pragma external_pred(link_error/2).