Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!hao!ames!amdahl!amdcad!tim
From: tim@amdcad.AMD.COM (Tim Olson)
Newsgroups: comp.lang.c
Subject: Re: Dhrystones
Message-ID: <19440@amdcad.AMD.COM>
Date: Fri, 4-Dec-87 15:14:32 EST
Article-I.D.: amdcad.19440
Posted: Fri Dec  4 15:14:32 1987
Date-Received: Wed, 9-Dec-87 05:40:43 EST
References: <3368@rosevax.Rosemount.COM> <5096@ccv.bbn.COM> <19425@amdcad.AMD.COM> <9613@mimsy.UUCP>
Reply-To: tim@amdcad.UUCP (Tim Olson)
Organization: Advanced Micro Devices
Lines: 44
Keywords: C, performance, useful

In article <9613@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
| In article <19425@amdcad.AMD.COM> tim@amdcad.AMD.COM (Tim Olson) writes:
| >... There exists quite a lot of "dead code" in Dhrystone
| >(expressions which aren't ever used) which good compilers can optimize
| >totally away.  This isn't the case with real-world code.
| 
| Are you sure?
| 
| (Change that to `good real-world code' and I will agree; change it to
| `most real-world code' and I am still uncertain.)

I mean code like:

Proc4()
{
	REG boolean	BoolLoc;

	BoolLoc = Char1Glob == 'A';	<-- these 2 expressions are
	BoolLoc |= BoolGlob;		<-- totally useless
	Char2Glob = 'B';
}


That is a very obvious example, but there are many other places, such as
in proc0:

		IntLoc3 = IntLoc2 * IntLoc1;
		IntLoc2 = IntLoc3 / IntLoc1;
		IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;

The first assignment into IntLoc2 is replaced in the next expression --
no need to calculate it (and we take a divide out of the loop -- big win ;-)
Actually, the second assignment into IntLoc2 doesn't need to be
performed, either, because it is to a register variable which isn't used
before it is assigned again.

This kind of code is not seen (I hope!) in real-world applications. 
Yes, there is still dead code there, but it falls more into the category
of previously live code that becomes dead, due to previous
optimizations.

	-- Tim Olson
	Advanced Micro Devices
	(tim@amdcad.amd.com)