From -1810263701508842128
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ccb764366ee3f529,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-04-08 08:05:01 PST
Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!telocity-west!TELOCITY!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!newspeer.clara.net!news.clara.net!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: John Nagle <nagle@animats.com>
Newsgroups: comp.std.c++
Subject: Proposal: allow code hoisting optimizatoin for "assert"
Date: Mon,  8 Apr 2002 15:04:09 GMT
Organization: Prodigy Internet http://www.prodigy.com
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3CB1290F.8000407@animats.com>
X-Trace: mail2news.demon.co.uk 1018278255 mail2news:12011 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)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1
X-Accept-Language: en-us
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: Mon, 08 Apr 2002 01:03:13 EDT
X-UserInfo1: FKPO@SBE[JTIRVX[]BCD^VX@WB]^PCPDLXUNNHLHEQR@ETUCCNSKQFCY@TXDX_WHSVB]ZEJLSNY\^J[CUVSA_QLFC^RQHUPH[P[NRWCCMLSNPOD_ESALHUK@TDFUZHBLJ\XGKL^NXA\EVHSP[D_C^B_^JCX^W]CHBAX]POG@SSAZQ\LE[DCNMUPG_VSC@VJM
Lines: 55
Xref: archiver1.google.com comp.std.c++:10429

    I'd like to propose that the following optimization
be allowed.  Consider

	for (int i=0; i<n; 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 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                       ]



