Bug 17102 - Missed constant folding opportunity
Summary: Missed constant folding opportunity
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P1 enhancement
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2004-08-19 14:59 UTC by Pete Steinmetz
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host: powerpc64-linux
Target: powerpc64-linux
Build: powerpc64-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pete Steinmetz 2004-08-19 14:59:11 UTC
Description:
A non-optimal code sequence is illustrated.    Duplicate using gcc 3.5 and
command line:

gcc -O3 -m64 -c test.c


Testcase:
#include "stdio.h"
const int C0 = 0;
const int C1 = 1;
const int C2 = 2;

void bar () {
  printf("bar\n");
}

void foo ()
{
  /* GCC is able to figure this one out, do constant
     folding and dead code elimination, and eliminate
     the entire block of code */
  if (1, 2, 0) bar ();

  /* .. it unsuccessfully resolves this one. */
  if (C1, C2, C0) bar ();
}

Assembly:
.foo:
      mflr 0
      ld 9,.LC2@toc(2)
      std 0,16(1)
      lwz 0,0(9)
      stdu 1,-112(1)
      cmpwi 7,0,0
      bne- 7,.L6
      addi 1,1,112
      ld 0,16(1)
      mtlr 0
      blr
.L6:
      ld 3,.LC3@toc(2)
      bl .puts
      nop
      addi 1,1,112
      ld 0,16(1)
      mtlr 0
      blr

Comment 1 Andrew Pinski 2004-08-19 15:14:14 UTC
Fixed between 20040721  and 20040725.