with Instrument;
use Instrument;

-----------------------
-- Unroll Scalar Reference
-----------------------

--  This test evaluates a code  improvement  potential  that  results
--  from  replicating  operations  when the opportunity is offered to
--  unroll a simple redefinition enclosed in a loop.

--  The test procedures contain a redefinition of a  local  variable,
--  Local_1,  enclosed by two loops.  The unrolling of the inner loop
--  in the optimized test procedure is evidenced by a  difference  in
--  the  execution time and space requirements of the two procedures.
--  The  redefinition  is  adequately  camouflaged  to  prevent   the
--  elimination of the inner loop in the optimized test procedure and
--  relocation  of  the  redefinition  in   the   nonoptimized   test
--  procedure.

--  The camouflaged redefinition of Global_1 using the local variable
--  ensures that other unexpected optimizations do not invalidate the
--  benchmark.

procedure Lousa2 is

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

    Local_1 : T := Ident (Init);

begin

    Start ("LOUSA2", "Loop Optimization, Unroll Scalar (test)");
    for I in 1 .. 10000 loop

        Let (Global, Ident (Init));

        for J in Ident (T (1)) .. Ident (T (10)) loop
            -- included in test version
            --  for J in Ident(T(1)) .. Ident(T(2)) loop  -- included in control version

            Unroll_Scalar_Assgnt:
                -- included in test version
                for K in 1 .. 2 loop
                    -- included in test version
                    --     for K in 1 .. 10 loop            -- included in control version

                    Local_1 := Ident (Local_1);

                end loop Unroll_Scalar_Assgnt;  -- included in test version

        end loop;

        Let (Global, Ident (Local_1));
        Let (Global, Ident (Init));

    end loop;
    Stop;

end Lousa2;