From 1265650383623510202 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,ccb764366ee3f529 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-04-10 05:37:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "Stephen Howe" Newsgroups: comp.std.c++ Subject: Re: Proposal: allow code hoisting optimizatoin for "assert" Date: Wed, 10 Apr 2002 12:36:04 GMT Organization: Taylor Nelson Sofres Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <3cb42fd1$0$8508$ed9e5944@reading.news.pipex.net> References: <3CB1290F.8000407@animats.com> Reply-To: "Stephen Howe" X-Trace: mail2news.demon.co.uk 1018442169 mail2news:9365 mail2news mail2news.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Lines: 74 Xref: archiver1.google.com comp.std.c++:10498 "John Nagle" wrote in message news:3CB1290F.8000407@animats.com... > I'd like to propose that the following optimization > be allowed. Consider > > for (int i=0; i { tab[i] = 0; } > > Now suppose that tab[i] is a class with subscript > checking, implemented as an assert. I'd like to > allow the compiler to hoist that assert out of the > loop. Rather than performing > > assert(i < tab.size()); > > every time through the loop, the compiler should > be allowed, if it's smart enough, to do > > assert(n <= tab.size()); > > at the beginning of the loop. But what if the [] operator changes the size on access? Unusual I know but possible. The assert() could not be hoisted then. Stephen Howe > > But right now, compilers can't do that. > Hoisting the assert out of the loop makes it > fail "early", which is an illegal optimization. > I suggest making it a legal one, and allow the > compiler to understand that "assert" is special. > > Specifically, > > A compiler should be allowed to recognize > "assert" at compile time. > > An assertion failure may be detected any time > after assertion failure becomes inevitable. > The compiler is not required to consider the > possibility that an exception will be raised > which prevent the assertion from failing. > > This lays the groundwork for efficient subscript, > checking. Old studies of Pascal programs indicated > that 95% of subscript checks could be hoisted out of > loops. Subscript checking has been implemented for > C++, but it's slow. This allows implementations > that do it fast. > > Comments? > > John Nagle > Animats > > --- > [ comp.std.c++ is moderated. To submit articles, try just posting with ] > [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] > [ --- Please see the FAQ before posting. --- ] > [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ] > --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]