Bug 15357 - [tree-ssa] combing if statements
Summary: [tree-ssa] combing if statements
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: tree-ssa
: P2 enhancement
Target Milestone: 4.9.0
Assignee: Andrew Pinski
URL:
Keywords: missed-optimization
Depends on: 29789 31657
Blocks: 13965 14052 15241 15348 15352 15353 15911 23869
  Show dependency treegraph
 
Reported: 2004-05-09 22:11 UTC by Andrew Pinski
Modified: 2013-11-09 20:39 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-03-05 17:33:05


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2004-05-09 22:11:17 UTC
The following two functions should give the same asm (If the branch cost is high 
enough):
int g(void);
int h(int a, int b, int c, int d)
{
  if (a==b)
   if (c==d)
     return g();
  return 0;
}
int h1(int a, int b, int c, int d)
{
  if (a==b && c==d)
    return g();
  return 0;
}

And these two:
int j(int a, int b, int c, int d)
{
  if (a==b)
   goto a;
  if (c==d)
   goto a;
  else
   goto b;
a:
  return g();
b:
  return 0;
}
int j1(int a, int b, int c, int d)
{
  if (a==b || c==d)
    return g();
  return 0;
}
Comment 1 Andrew Pinski 2004-05-09 22:20:20 UTC
Mine I am working on this, then we should be able to removed this optimization in fold 
which causes this to happen in the one statement one.
Comment 2 Andrew Pinski 2005-05-08 18:17:30 UTC
I lost the code which I was using to do this so I am no longer working on this.
Comment 3 Richard Biener 2007-01-26 13:44:25 UTC
Another thing we should be able to do is combine bit-tests like

 if (a & (1 << b))
   if (a & (1 << c))
     ...

to a single test

 if (a & ((1 << b) | (1 << c)) == ((1 << b) | (1 << c)))
   ...
Comment 4 Richard Biener 2007-06-12 12:10:46 UTC
The new if-combining pass can be told to make the transformation suggested in
the description.
Comment 5 Andrew Pinski 2012-01-21 22:02:24 UTC
I have a patch which implements this.  I will be posting it for 4.8.
Comment 6 Andrew Pinski 2013-11-09 20:39:51 UTC
Fixed by:
2013-10-29  Andrew Pinski <apinski@cavium.com>

        * tree-ssa-ifcombine.c: Include rtl.h and tm_p.h.
        (ifcombine_ifandif): Handle cases where maybe_fold_and_comparisons
        fails, combining the branches anyways.
        (tree_ssa_ifcombine): Inverse the order of the basic block walk,
        increases the number of combinings.
        * gimple.h (gsi_start_nondebug_after_labels_bb): New function.