From: Gabriel Dos Reis <Gabriel.Dos-Reis@dptmaths.ens-cachan.fr>
To: Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>
Cc: Gabriel.Dos-Reis@dptmaths.ens-cachan.fr, egcs@cygnus.com
Subject: Re: EGCS bad on loop invariant optimization ?
Date: Tue, 21 Apr 1998 17:06:00 -0000 [thread overview]
Message-ID: <199804211512.RAA18291@piano.dptmaths.ens-cachan.fr> (raw)
In-Reply-To: <199804192253.AAA30300@mira.isdn.cs.tu-berlin.de>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1955 bytes --]
>>>>> «Martin», Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de> wrote:
[code snipped]
>> Can't EGCS see that a.data, b.data, c.data are loop invariants and
>> then move the loads out of the loop ? At least, one can expect
>> b.data and c.data to be subject of this kind of optimization since the
>> only way to access them is through the (leaf) *const* class member
>> fonction `array::operator[](size_t) const'. What am I missing ?
Martin> I believe this would depend on how ::operator new is implemented. It
Martin> *could* return pointers into the stack, so that the writes to a[i]
Martin> overwrite the contents of b and c, so that reloading b.date and c.data
Martin> is necessary.
Martin> Of course, ::operator new never does such things. g++ doesn't now
Martin> that, though, and assumes worst-case.
Hmm. I can't get the point. Let me show my ignorance. Consider the
following code:
inline double& nth_element(double* data, unsigned i)
{ return data[i]; }
inline double nth_element(const double* data, unsigned i)
{ return data[i]; }
int main()
{
const unsigned n = 1000;
double* a = new double[n];
double* b = new double[n];
double* c = new double[n];
for (unsigned i=0; i<n; ++i)
nth_element(a, i) = nth_element(static_cast<const double*>(b), i)
+ nth_element(static_cast<const double*>(c), i);
return 0;
}
EGCS-980325 with -O option outputs:
main:
.LLFB1:
!#PROLOGUE# 0
save %sp,-112,%sp
.LLCFI0:
!#PROLOGUE# 1
sethi %hi(8000),%l0
call __builtin_vec_new,0
or %l0,%lo(8000),%o0
mov %o0,%l1
call __builtin_vec_new,0
or %l0,%lo(8000),%o0
mov %o0,%i0
call __builtin_vec_new,0
or %l0,%lo(8000),%o0
mov %o0,%o2
mov 0,%o1
.LL9:
sll %o1,3,%o0
ldd [%i0+%o0],%f2
ldd [%o2+%o0],%f4
faddd %f2,%f4,%f2
add %o1,1,%o1
cmp %o1,999
bleu .LL9
std %f2,[%l1+%o0]
ret
restore %g0,0,%o0
As you can see, there is no store/load of a, b and c inside the loop.
-- Gaby
next prev parent reply other threads:[~1998-04-21 17:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-04-19 10:52 Gabriel Dos Reis
1998-04-19 15:57 ` John Carr
1998-04-20 21:13 ` Jeffrey A Law
1998-04-21 7:36 ` Gabriel Dos Reis
1998-04-21 13:29 ` Gabriel Dos Reis
1998-04-19 18:48 ` Martin von Loewis
1998-04-21 17:06 ` Gabriel Dos Reis [this message]
1998-04-23 6:57 ` Martin von Loewis
1998-04-24 10:11 ` Gabriel Dos Reis
1998-04-24 16:23 ` Martin von Loewis
1998-04-25 9:37 ` Gabriel Dos Reis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199804211512.RAA18291@piano.dptmaths.ens-cachan.fr \
--to=gabriel.dos-reis@dptmaths.ens-cachan.fr \
--cc=egcs@cygnus.com \
--cc=martin@mira.isdn.cs.tu-berlin.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).