Re: Optimization techniques and undefined behavior

Martin Ward <martin@gkc.org.uk>
Thu, 2 May 2019 14:54:46 +0100

          From comp.compilers

Related articles
[7 earlier articles]
Re: Optimization techniques and undefined behavior bc@freeuk.com (Bart) (2019-04-29)
Re: Optimization techniques and undefined behavior david.brown@hesbynett.no (David Brown) (2019-04-30)
Re: Optimization techniques and undefined behavior david.brown@hesbynett.no (David Brown) (2019-04-30)
Re: Optimization techniques and undefined behavior bc@freeuk.com (Bart) (2019-05-01)
Re: Optimization techniques and undefined behavior bc@freeuk.com (Bart) (2019-05-01)
Re: Optimization techniques and undefined behavior anw@cuboid.co.uk (Andy Walker) (2019-05-02)
Re: Optimization techniques and undefined behavior martin@gkc.org.uk (Martin Ward) (2019-05-02)
Re: Optimization techniques and undefined behavior david.brown@hesbynett.no (David Brown) (2019-05-02)
Re: Optimization techniques and undefined behavior david.brown@hesbynett.no (David Brown) (2019-05-02)
Re: Optimization techniques and undefined behavior 847-115-0292@kylheku.com (Kaz Kylheku) (2019-05-02)
Re: Optimization techniques and undefined behavior bc@freeuk.com (Bart) (2019-05-02)
Re: Optimization techniques and undefined behavior bc@freeuk.com (Bart) (2019-05-02)
Re: Optimization techniques and undefined behavior auriocus@gmx.de (Christian Gollwitzer) (2019-05-02)
[20 later articles]
| List of all articles for this month |
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


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.