Bug 19940 - Missed jump threading opportunity due to |.
Summary: Missed jump threading opportunity due to |.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P2 enhancement
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, TREE
Depends on: 18832
Blocks: jumpthreading
  Show dependency treegraph
 
Reported: 2005-02-13 18:35 UTC by Kazu Hirata
Modified: 2005-07-25 17:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-23 05:35:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2005-02-13 18:35:15 UTC
Consider:

void bar (void);

int global;

void
foo (unsigned char pedwarned, unsigned char warned)
{
  unsigned char tem = warned | pedwarned;

  if (tem == 0)
    {
      if (global)
	warned = 1;
    }

  tem = warned | pedwarned;
  if (tem != 0)
    bar ();
}

Notice that if we get to "warned = 1;", we know we are going to call bar.
However, the tree optimizers do not notice this.

The RTL optimizers do find this optimization opportunity.

Reduced from c-decl.c:duplicate_decls.
Comment 1 Andrew Pinski 2005-02-13 18:59:09 UTC
Confirmed, related to PR 18832.

Note on PPC at least we don't really thread the jumps that well on the rtl level:
_foo:
        or. r0,r4,r3
        bne- cr0,L2
        lis r2,ha16(_global)
        ori r0,r3,1
        lwz r2,lo16(_global)(r2)
        cmpwi cr6,r0,0
        cmpwi cr7,r2,0
        beqlr- cr7
        beqlr- cr6
L2:
        b _bar

Now if we change all the unsigned char to _Bool we get the threaded jump:
_foo:
        or. r0,r4,r3
        bne- cr0,L2
        lis r2,ha16(_global)
        lwz r2,lo16(_global)(r2)
        cmpwi cr7,r2,0
        beqlr- cr7
L2:
        b _bar
Comment 2 Steven Bosscher 2005-04-23 17:03:23 UTC
This is not fixed by Jeff's latest threader patch. 
Comment 3 Jeffrey A. Law 2005-04-25 05:09:10 UTC
Correct, it's not fixed.  I have an idea why, but haven't really investigated
yet.

Comment 4 Steven Bosscher 2005-07-25 16:59:30 UTC
This appears to work now... 
Comment 5 Andrew Pinski 2005-07-25 17:07:38 UTC
Confirmed as fixed.