Article View: comp.lang.misc
Article #5655Re: Query re optimising compilers
From: 00704a-Liber
Date: Mon, 25 Jul 1988 19:24
Date: Mon, 25 Jul 1988 19:24
36 lines
1728 bytes
1728 bytes
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. / (_</_\/ <__/ / <_ These are solely MY opinions, not AT&T's, blah blah blah
Technical Details
Message-ID:
<5423@ihlpf.ATT.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!ihnp4!ihlpf!nevin1References:
<561@etive.ed.ac.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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