Path: utzoo!utgpu!water!watmath!clyde!att!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.misc Subject: Re: Query re optimising compilers Message-ID: <5423@ihlpf.ATT.COM> Date: 25 Jul 88 19:24:40 GMT References: <561@etive.ed.ac.uk> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 36 In article <561@etive.ed.ac.uk> db@lfcs.ed.ac.uk (Dave Berry) writes: |Would it be sensible to optimise the following code: |a := function (); |b := (complicated expression) * a; |to the equivalent of: |a:= function (); |if (a == 0) | b := 0; |else | (complicated expression) * a; |Assuming: | the result returned by "function" is a very small integer (including 0), | and isn't known at compile-time | "complicated_expression" has no side-effects and would take much longer | to evaluate than a comparison with 0. | the time taken to compile a program isn't considered. This is not a good optimization, unless the compiler can determine at compile time that 'a' is much more likely to be 0 than not. Since this is very difficult to determine at compile time, it is usually not done. Note: if you know that 'a' is going to be 0 most of the time it might pay to recode your first example into your second example. But you have to make the choice, not the compiler, since this involves information that is not (usually) known to the compiler. -- _ __ NEVIN J. LIBER ..!att!ihlpf!nevin1 (312) 979-???? ' ) ) You are in a maze of little twisting / / _ , __o ____ email paths, all different. / (_