Bug 31631 - Folding of A & (1 << B) pessimizes FRE
Summary: Folding of A & (1 << B) pessimizes FRE
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2007-04-19 10:56 UTC by Richard Biener
Modified: 2008-01-03 15:06 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-03 15:06:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2007-04-19 10:56:48 UTC
void
foo (int control2, unsigned long *state, int size)
{
  int i;

  for(i=0; i<size; i++)
    {
       if (state[i] & ((unsigned long) 1 << control2))
         state[i] ^= ((unsigned long) 1 << control2);
    }
}

FRE does not recognize the ((unsigned long) 1 << control2) redundancy
because it looks like

<L0>:;
  D.1989_4 = (long unsigned int) i_1;
  D.1990_5 = D.1989_4 * 8;
  D.1991_6 = (long unsigned int *) D.1990_5;
  D.1992_8 = D.1991_6 + state_7(D);
  # VUSE <SMT.4_28>
  D.1993_9 = *D.1992_8;
  D.1994_11 = D.1993_9 >> control2_10(D);
  D.1995_12 = (int) D.1994_11;
  D.1996_13 = D.1995_12 & 1;
  if (D.1996_13 != 0) goto <L1>; else goto <L2>;
  
<L1>:;
  D.1989_19 = D.1989_4;
  D.1990_20 = D.1990_5;
  D.1991_21 = D.1991_6;
  D.1992_22 = D.1992_8;
  D.1993_23 = D.1993_9;
  D.1998_24 = 1 << control2_10(D);
  D.1999_25 = D.1993_23 ^ D.1998_24;
  # SMT.4_30 = VDEF <SMT.4_28>
  *D.1992_22 = D.1999_25;

This is related to PR29789 where this transformation causes other
pessimization.
Comment 1 Richard Biener 2008-01-03 15:06:46 UTC
Confirmed.  LIM and DOM together remove the redundancy later.  If the loop
enclosing the redundancy is removed this doesn't happen.