Bug 15348

Summary: [tree-ssa] Convert (x < 0) || (y < 0) into (x | y) < 0.
Product: gcc Reporter: Kazu Hirata <kazu>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: allen_1985624, dimhen, gabravier, gcc-bugs, jeffreyalaw, zhongyunde
Priority: P2 Keywords: missed-optimization
Version: tree-ssa   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-12-30 22:22:49
Bug Depends on: 15357, 15459    
Bug Blocks: 19987    

Description Kazu Hirata 2004-05-09 19:30:50 UTC
Convert foo() into baz().

void bar (void);

int
foo (int x, int y)
{
  int t1 = x < 0;
  int t2 = y < 0;
  return t1 || t2;
}

int
baz (int x, int y)
{
  return (x | y) < 0;
}

Needless to mention, we should do this fairly late in SSA optimizations.
Comment 1 Kazu Hirata 2004-05-09 19:32:30 UTC
Another one just like above:

void bar (void);

void
foo (int a, int b)
{
  if (a != 0)
    return;
  if (b != 0)
    return;
  bar ();
}

void
baz (int a, int b)
{
  if ((a | b) == 0)
    bar ();
}

See also PR 15241.
Comment 2 Andrew Pinski 2004-05-09 19:41:56 UTC
Confirmed.  
Comment 3 Steven Bosscher 2005-09-30 22:29:24 UTC
For AMD64, the functions from the first test case don't produce the 
same code either, so combine is not catching this either. 
 
Comment 4 Dmitry G. Dyachenko 2020-03-11 07:06:16 UTC
x86_64 r10-7080 for me produce identical code
-- c#0 with -O2
-- c#1 with -O
Comment 5 Jeffrey A. Law 2020-04-19 18:17:42 UTC
Resolved at some point in the past.  Not worth the trouble to bisect.