with Instrument;
use Instrument;

----------
-- Assignment
----------

--  This test evaluates a code  improvement  potential  that  results
--  from  simplifying  loop  computations  when  the  opportunity  is
--  offered to relocate all repetitive operations  outside  the  code
--  region of a loop body.

--  The two  test  procedures  contain  a  single  loop  enclosing  a
--  redefinition   of  a  local  variable.   In  the  optimized  test
--  procedure the redefinition uses an invariant  expression  whereas
--  the   nonoptimized   test   procedure  uses  an  expression  that
--  references  the  redefined  local  variable.   Consequently,  the
--  optimization  is  evidenced by a difference in both the execution
--  time and space requirements of the two procedures since the  loop
--  can be simplified when the redefinition is invariant.

--  Because of the camouflaged evaluation of the discrete range,  all
--  loop   operations   cannot   be   eliminated.    The  camouflaged
--  redefinition of Global_1 ensures that the  loop  redefinition  is
--  not eliminated from both test procedures.

procedure Loaea2 is

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

    One : constant T := T (Init / Init);
    Two : constant T := One + One;

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

begin

    Start ("LOAEA2", "Loop Optimization, Asst. Eval. (test)");
    for I in 1 .. 10000 loop

        Let (Global, Ident (Init));

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

            ---------------optimize----------------
            Local_1 := T ((Local_2 + Local_3) /
                          Two);  -- included in test version
            --     Local_2 := T((Local_2 + Local_3) / Two);  -- included in control version

        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 Loaea2;