with Instrument;
use Instrument;

-----------------------------
-- Nested Expression Computation
-----------------------------

--  This test evaluates a code improvement potential similar to  that
--  resulting from the Expression Computation benchmark.

--  The  two  test  procedures  are  identical  to   the   Expression
--  Computation  test  procedures  except that the loop enclosing the
--  redefinition of Local_1 is enclosed within an outer loop in  each
--  procedure.   Consequently,  in  the  optimized test procedure the
--  opportunity is offered  to  relocate  the  invariant  computation
--  outside of the two loop bodies and is evidenced by an increase in
--  the difference in the execution times of the two procedures.

--  The camouflaged discrete ranges of the two loops  safeguard  loop
--  transformations that would invalidate the benchmark.

procedure Lonea2 is

    package New_Procs is new Procs (Integer);
    use New_Procs;

    Local_1, Local_2, Local_3 : T := Ident (Init / Init);

begin

    Start ("LONEA2", "Loop Optimization, Nested Expr. comp. (test)");
    for I in 1 .. 1000 loop

        Let (Global, Ident (Init));

        for J in Ident (T'Val (1)) .. Ident (T'Val (10)) loop

            for K in Ident (T'Val (1)) .. Ident (T'Val (10)) loop

                -----optimize----
                Let (Local_1, Ident (T (T (Local_2 * Local_3) / Local_1)));
                -- included in test version
                --        Let(Local_2, Ident(T(T(Local_2 * Local_3)/Local_1)));
                -- included in control version

            end loop;

        end loop;

        Let (Global, Ident (Local_1));         -- included in test version
        --  Let(Global, Ident(Local_2));         -- included in control version

        Let (Global, Ident (Init));

    end loop;
    Stop;

end Lonea2;