From: | Martin Ward <martin@gkc.org.uk> |
Newsgroups: | comp.compilers |
Date: | Thu, 2 May 2019 14:54:46 +0100 |
Organization: | Compilers Central |
References: | 19-05-003 19-04-021 19-04-023 19-04-037 19-04-039 19-04-042 19-04-045 19-04-049 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="66462"; mail-complaints-to="abuse@iecc.com" |
Keywords: | optimize, arithmetic, errors |
Posted-Date: | 02 May 2019 12:09:37 EDT |
On 01/05/19 12:40, Bart wrote:
> for (int i=0; i<1000000000; ++i) {
> y=x*3/3;
> z+=y;
> ++x;
> }
Given that gcc can optimise y=x*3/3 to y=x
I would have expected the whole loop to be recognised
as computing the sum of an arithmetic sequence
and therefore optimised away completely.
This blog post:
https://xebia.com/blog/gcc-compiler-optimizations-dissection-of-a-benchmark/
discusses a program with the loop:
for( a = 0; a < arg1; a++ )
{
sum += a;
}
and claims that gcc with -O3 will optimise
the loop to take only costant time.
But this is not the case on my machine with gcc 4.9.2
--
Martin
Dr Martin Ward | Email: martin@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4
Return to the
comp.compilers page.
Search the
comp.compilers archives again.