comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent Guerby <guerby@acm.org>
Subject: Right of Optimize Eager Evaluation Away
Date: 1999/11/28
Date: 1999-11-28T18:46:08+00:00	[thread overview]
Message-ID: <863dtqfo26.fsf@ppp-173-146.villette.club-internet.fr> (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




             reply	other threads:[~1999-11-28  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-28  0:00 Laurent Guerby [this message]
1999-11-28  0:00 ` Right of Optimize Eager Evaluation Away 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
replies disabled

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