public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/46076] New: [4.6 regression] constant propogation and compile-time math no longer happening versus 4.4 and 4.5
@ 2010-10-18 21:01 matt at use dot net
  2010-10-18 21:15 ` [Bug middle-end/46076] " pinskia at gcc dot gnu.org
                   ` (35 more replies)
  0 siblings, 36 replies; 37+ messages in thread
From: matt at use dot net @ 2010-10-18 21:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46076

           Summary: [4.6 regression] constant propogation and compile-time
                    math no longer happening versus 4.4 and 4.5
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: matt@use.net


For the following code:


#include <stdio.h>

typedef unsigned char(*Calculable)(void);

static unsigned char one() { return 1; }
static unsigned char two() { return 2; }

static void print(Calculable calculate)
{
    printf("%d\n", calculate());
    printf("+1: %d\n", calculate() + 1);
}

int main()
{
    print(one);
    print(two);

    return 0;
}


GCC 4.4 (Ubuntu/Linaro 4.4.4-14ubuntu5) and 4.5(Ubuntu/Linaro 4.5.1-7ubuntu2),
when using -O3 on amd64 using Ubuntu 10.10's packages, produce the following
code:


00000000004005a0 <main>:
  4005a0:       48 83 ec 08             sub    rsp,0x8
  4005a4:       ba 01 00 00 00          mov    edx,0x1
  4005a9:       be 00 07 40 00          mov    esi,0x400700
  4005ae:       bf 01 00 00 00          mov    edi,0x1
  4005b3:       31 c0                   xor    eax,eax
  4005b5:       e8 ae fe ff ff          call   400468 <__printf_chk@plt>
  4005ba:       ba 02 00 00 00          mov    edx,0x2
  4005bf:       be fc 06 40 00          mov    esi,0x4006fc
  4005c4:       bf 01 00 00 00          mov    edi,0x1
  4005c9:       31 c0                   xor    eax,eax
  4005cb:       e8 98 fe ff ff          call   400468 <__printf_chk@plt>
  4005d0:       ba 02 00 00 00          mov    edx,0x2
  4005d5:       be 00 07 40 00          mov    esi,0x400700
  4005da:       bf 01 00 00 00          mov    edi,0x1
  4005df:       31 c0                   xor    eax,eax
  4005e1:       e8 82 fe ff ff          call   400468 <__printf_chk@plt>
  4005e6:       ba 03 00 00 00          mov    edx,0x3
  4005eb:       be fc 06 40 00          mov    esi,0x4006fc
  4005f0:       bf 01 00 00 00          mov    edi,0x1
  4005f5:       31 c0                   xor    eax,eax
  4005f7:       e8 6c fe ff ff          call   400468 <__printf_chk@plt>
  4005fc:       31 c0                   xor    eax,eax
  4005fe:       48 83 c4 08             add    rsp,0x8
  400602:       c3                      ret    

where the constants are correctly propogated and the compile-time math occurs.

With Ubuntu 10.10's gcc-snapshot of 4.6 (Ubuntu 20101004-0ubuntu1) or an
alternate 4.6 version (Sourcery G++ 2010.09-31), neither of these things
happens, even with -fwhole-program:

0000000000400510 <_ZL3onev>:
  400510:       b8 01 00 00 00          mov    eax,0x1
  400515:       c3                      ret    
  400516:       eb 08                   jmp    400520 <_ZL3twov>
  400518:       90                      nop
  400519:       90                      nop
  40051a:       90                      nop
  40051b:       90                      nop
  40051c:       90                      nop
  40051d:       90                      nop
  40051e:       90                      nop
  40051f:       90                      nop

0000000000400520 <_ZL3twov>:
  400520:       b8 02 00 00 00          mov    eax,0x2
  400525:       c3                      ret    
  400526:       eb 08                   jmp    400530 <_ZL5printPFhvE>
  400528:       90                      nop
  400529:       90                      nop
  40052a:       90                      nop
  40052b:       90                      nop
  40052c:       90                      nop
  40052d:       90                      nop
  40052e:       90                      nop
  40052f:       90                      nop

0000000000400530 <_ZL5printPFhvE>:
  400530:       53                      push   rbx
  400531:       48 89 fb                mov    rbx,rdi
  400534:       ff d7                   call   rdi
  400536:       bf 74 06 40 00          mov    edi,0x400674
  40053b:       0f b6 f0                movzx  esi,al
  40053e:       31 c0                   xor    eax,eax
  400540:       e8 b3 fe ff ff          call   4003f8 <printf@plt>
  400545:       ff d3                   call   rbx
  400547:       5b                      pop    rbx
  400548:       0f b6 f0                movzx  esi,al
  40054b:       bf 70 06 40 00          mov    edi,0x400670
  400550:       31 c0                   xor    eax,eax
  400552:       83 c6 01                add    esi,0x1
  400555:       e9 9e fe ff ff          jmp    4003f8 <printf@plt>
  40055a:       eb 04                   jmp    400560 <main>
  40055c:       90                      nop
  40055d:       90                      nop
  40055e:       90                      nop
  40055f:       90                      nop

0000000000400560 <main>:
  400560:       48 83 ec 08             sub    rsp,0x8
  400564:       bf 10 05 40 00          mov    edi,0x400510
  400569:       e8 c2 ff ff ff          call   400530 <_ZL5printPFhvE>
  40056e:       bf 20 05 40 00          mov    edi,0x400520
  400573:       e8 b8 ff ff ff          call   400530 <_ZL5printPFhvE>
  400578:       31 c0                   xor    eax,eax
  40057a:       48 83 c4 08             add    rsp,0x8
  40057e:       c3                      ret


^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2012-03-26  6:53 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-18 21:01 [Bug middle-end/46076] New: [4.6 regression] constant propogation and compile-time math no longer happening versus 4.4 and 4.5 matt at use dot net
2010-10-18 21:15 ` [Bug middle-end/46076] " pinskia at gcc dot gnu.org
2010-10-18 21:36 ` matt at use dot net
2010-10-19  0:20 ` [Bug middle-end/46076] [4.6 regression] constant propagation " hjl.tools at gmail dot com
2010-10-19  3:21 ` hubicka at gcc dot gnu.org
2010-10-19  3:25 ` hubicka at gcc dot gnu.org
2010-10-19  3:33 ` hubicka at gcc dot gnu.org
2010-10-19  4:43 ` pinskia at gcc dot gnu.org
2010-10-19  5:47 ` hubicka at ucw dot cz
     [not found] ` <20101019044304.166D0F0158@atrey.karlin.mff.cuni.cz>
2010-10-19  5:47   ` Jan Hubicka
2010-10-19 10:52 ` rguenth at gcc dot gnu.org
2010-10-20  8:22 ` jakub at gcc dot gnu.org
2010-11-04 13:05 ` [Bug c/46076] " rguenth at gcc dot gnu.org
2010-11-04 13:55 ` joseph at codesourcery dot com
2010-11-17 21:39 ` matt at use dot net
2010-11-18 11:53 ` rguenther at suse dot de
2010-11-18 12:12 ` hubicka at ucw dot cz
2010-11-18 12:23 ` rguenth at gcc dot gnu.org
2011-01-04 17:40 ` jamborm at gcc dot gnu.org
2011-01-11 14:44 ` rguenth at gcc dot gnu.org
2011-01-11 15:41 ` joseph at codesourcery dot com
2011-01-11 16:27 ` rguenth at gcc dot gnu.org
2011-01-11 17:03 ` rguenth at gcc dot gnu.org
2011-01-11 17:30 ` rguenth at gcc dot gnu.org
2011-01-14 13:04 ` rguenth at gcc dot gnu.org
2011-01-14 13:08 ` rguenth at gcc dot gnu.org
2011-03-25 21:14 ` [Bug c/46076] [4.6/4.7 " jakub at gcc dot gnu.org
2011-04-12 10:44 ` rguenth at gcc dot gnu.org
2011-04-12 16:24 ` matt at use dot net
2011-04-12 17:39 ` jakub at gcc dot gnu.org
2011-04-12 18:15 ` matt at use dot net
2011-04-12 22:32 ` rguenther at suse dot de
2011-06-27 16:22 ` [Bug tree-optimization/46076] [4.6 " jakub at gcc dot gnu.org
2011-10-26 17:56 ` jakub at gcc dot gnu.org
2012-03-01 15:20 ` jakub at gcc dot gnu.org
2012-03-23 20:35 ` matt at use dot net
2012-03-26  7:06 ` rguenth at gcc dot gnu.org

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).