From -564861454353879676
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7522e5259f7267d6
X-Google-Attributes: gidf78e5,public
From: jpotter@falcon.lhup.edu (John Potter)
Subject: Re: x = y = z;  Undefined?
Date: 2000/01/11
Message-ID: <3879ca08.3142429@news.csrlink.net>#1/1
X-Deja-AN: 570713747
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <MPG.12ddaa92533ae9679896a6@news.supernews.com> <t7so0bqea7.fsf@calumny.jyacc.com> <3876254a.30903561@news.csrlink.net> <derobert-9FC87E.01591309012000@news.erols.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 947512967 mail2news:5192 mail2news mail2news.demon.co.uk
Organization: Newscene Public Access Usenet News Service (http://www.newscene.com/)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Nntp-Posting-Date: Mon, 10 Jan 2000 06:34:50 CST
Newsgroups: comp.std.c++

On Mon, 10 Jan 2000 08:28:54 CST, Anthony DeRobertis
<derobert@erols.com> wrote:

: In article <3876254a.30903561@news.csrlink.net>, 
: jpotter@falcon.lhup.edu (John Potter) wrote:
: 
: 
: >could someone give an example of translation which would produce
: >something other than expected?
: >
: >   (i1 = i2) += i3;
: 
: Well, on my PowerPC this would generate (unoptimized):
: -- sequence point --
: or i1,i2,i2
: add i1,i1,i3
: -- sequence point --
: 
: Which could legally be re-arranged:
: add i1,i1,i3
: or i1, i2, i2

I don't think so.

  i3 += i1 = i2;

  or i1,i2,i2
  add i3,i3,i1

Re-arrangement violates the semantics of the language in both cases.
The implementation is allowed to assume that no stored value is
modified more than once.  I guess that you could stretch it to the
point of being allowed to detect an expression which invokes
undefined behavior and generate purposely bad code; however, the
compiler writers are in the business of selling compilers not
harassing users.  In both cases, the second instruction uses the
value of the first instruction.

: Which could then be optimized:
: or i1, i2, i2
: 
: Which means:
:    i1 = i2;
: 
: As there are no sequencing points. This could concievably be done for 
: scheduling purposes. I don't seem to be able to get my compile to do it 

I'm not surprised.

: (it does even weirder stuff...)

Given i2 == 2 and i3 == 3, does it do anything which produces other
than i1 == 5?  Assuming, of course, that there is a reason to do
anything.

My compiler nicely optimized
void f () { int i1, i2(2), i3(3); (i1 = i2) += i3; }
to
void f () { }

Changing to int f () and adding return i1, it optimized to return 5.

int f (int i2, int i3) { int i1; (i1 = i2) += i3; return i1; }
optimized to
add r3,r3,r4
which is i1 = i2 + i3.

Streatching my imagination, thanks to James Kanze
  load r1,i2
  copy r2,r1
  add  r2,i3
  sto  i1,r2
  sto  i1,r1
is a valid translation.  With multiprocessors, the last two
instructions could be executed in parallel opening the door
for many results depending on the hardware.

The ++ ++ i example also has strange valid translations.

I'm convinced, finally.

John

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]




