Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!homxb!genesis!hotlg!anumb!eao From: eao@anumb.UUCP (e.a.olson) Newsgroups: comp.lang.c Subject: Re: Bad optimizations (was Re: comma operator) Message-ID: <156@anumb.UUCP> Date: 23 Jan 88 14:49:19 GMT References: <3819@sigi.Colorado.EDU> <5080013@hpfcdc.HP.COM> <7120@brl-smoke.ARPA> <3887@sigi.Colorado.EDU> <269@vsi1.UUCP> <179@oravax.UUCP> Reply-To: eao@anumb.UUCP (e.a.olson) Organization: Rock 'n Roll Rest Home at Wierd Hill, MA Lines: 28 In article <179@oravax.UUCP> clay@oravax.odyssey.UUCP (Clay Brooke-McFarland) writes: >In article <269@vsi1.UUCP> steve@vsi1.UUCP (Steve Maurer) writes: >>SWARBRICK FRANCIS JOHN writes: >>> >>> #define swap(a,b) ((a) = ((b) = ((a) = (a) ^ (b)) ^ (b)) ^ (a)) >>> >>> >> [...] However, just to try this out, I decided to compile the >>following section of code on our Sun3 (without optimization). >> (Code deleted) >>The resulting code is approximately 3 times longer! This is >>partly due to the superflous storing of intermediate results that >>the compiler makes, [ ... ] I tried it on a 3B2, with and without optimization. In both cases the swap-macro version lost to the temp-variable version. The macro version optimized into three XORW instructions, and was only eight bytes longer than the optimized temp-var version. However, in the temp-var version the optimizer realized that it was going to be pushing the variables on the stack for a printf and decided not to bother with any moves and just pushed the variables on the stack in the order that would have been proper IF it had done the swap mvuxq!eao