Path: utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!decvax!dartvax!eleazar!davidg From: davidg@eleazar.Dartmouth.EDU (David Gelhar) Newsgroups: comp.arch Subject: Re: taken -vs- untaken branches Message-ID: <7891@eleazar.Dartmouth.EDU> Date: 9 Jan 88 04:36:06 GMT References: <496@cresswell.quintus.UUCP> <638@l.cc.purdue.edu> <20339@amdahl.amdahl.com> Reply-To: davidg@eleazar.Dartmouth.EDU (David Gelhar) Organization: Dartmouth College, Hanover, NH Lines: 27 In article <20339@amdahl.amdahl.com> chuck@amdahl.amdahl.com (Charles Simmons) writes: >[...]to estimate the number of legal values that one side of the expression >can take on, and the number of legal values that the other side of >the expression can take on. These two estimates can then be used >to estimate how often the expression will be TRUE. >For example, consider the fragment of code: > if (p == NULL) { > ... > } >Here, the compiler might think "'p' can take on 2**32 values, >NULL can take on one value, so the estimated number of times >these two expressions are equal is 1/2**32. Since this number >is less than 1/2, the condition will usually be false." This code fragment strikes me as an excellent example of where this heuristic would NOT produce useful results; I think it's pretty clear that in practice the values of pointer variables are not evenly distributed over the 2**32 possibilities. In fact, my estimate of the probability of an arbitrary pointer being NULL is more like 1/2 than 1/2**32. (Hmmmm... I guess that doesn't help much in predicting which way the branch will go, eh? :-)). (Hi chuck.)