comp.lang.ada
 help / color / mirror / Atom feed
* Right of Optimize Eager Evaluation Away
@ 1999-11-28  0:00 Laurent Guerby
  1999-11-28  0:00 ` Robert A Duff
  1999-11-29  0:00 ` Jean-Pierre Rosen
  0 siblings, 2 replies; 11+ messages in thread
From: Laurent Guerby @ 1999-11-28  0:00 UTC (permalink / raw)


[I originally posted this in the 11.6 thread, but got no answer]

If we have the following function:
   
   function Cond_T (C : in Boolean; If_True, If_False : in T) return T;
   pragma Inline (Cond_T);

   function Cond_T (C : in Boolean; If_True, If_False : in T) return T is
   begin
      if C then
         return If_True;
      else
         return If_False;
      end if;
   end Cond_T;

And the following expression:

   C : constant Boolean := Some_Run_Time_Value_That_The_Compiler_Cannot_Guess;

   X : constant T := Cont_T (C, If_True => Super_Expensive_Function_Call_1, 
                                If_False => Super_Expensive_Function_Call_2);

The question is: is a smart Ada 95 compiler allowed to generate code
that looks like this:

   if C then
      X := Super_Expensive_Function_Call_1;
   else
      X := Super_Expensive_Function_Call_2;
   end if;

that is to say, be lazy about its argument, and so might
save execution time.

If one of the Super_Expensive function has side effects, or raises an
exception (so Pure won't help here), the code is not identical to the
original code:

   X1 := Super_Expensive_Function_Call_1;
   X2 := Super_Expensive_Function_Call_2;
   if C then
      return X1;
   else
      return X2;
   end if;

--LG




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~1999-11-30  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-28  0:00 Right of Optimize Eager Evaluation Away Laurent Guerby
1999-11-28  0:00 ` Robert A Duff
1999-11-28  0:00   ` Laurent Guerby
1999-11-29  0:00     ` Nick Roberts
1999-11-29  0:00       ` Robert A Duff
1999-11-29  0:00         ` Laurent Guerby
1999-11-29  0:00           ` Lutz Donnerhacke
1999-11-29  0:00           ` Robert A Duff
1999-11-30  0:00             ` Laurent Guerby
1999-11-29  0:00           ` Niklas Holsti
1999-11-29  0:00 ` Jean-Pierre Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox