with Instrument;
use Instrument;

----------------------
-- Unroll Index Reference
----------------------

--  This test evaluates a code improvement potential similar to  that
--  resulting  from the Unroll Scalar Reference benchmark except that
--  the redefinition references a loop parameter.

--  The test procedures contain a redefinition  of  components  of  a
--  local  array.   Each  component  of  the array is identified by a
--  subscript expression that uses the  inner  loop  parameter.   The
--  local  array  is  defined  so  that  the  range  of  its index is
--  consistent with the larger of  the  two  loop  parameter  ranges.
--  Consequently,  in the optimized test procedure the opportunity to
--  individualize the redefinition of the appropriate subset  of  the
--  array  is  evidenced by a difference in the execution time of the
--  two procedures.
--
--  in order to prevent other unexpected optimizations.

procedure Louia2 is

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

    Local : array (1 .. 10) of T := (others => Ident (Init));

begin

    Start ("LOUIA2", "Loop Optimization, Unroll Index ref. (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_Array_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 (K) := Ident (Local (K));

                end loop Unroll_Array_Assgnt;           -- included in test version

        end loop;

        Let (Global, Ident (Local (1)));
        Let (Global, Ident (Init));

    end loop;
    Stop;

end Louia2;