https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119988

            Bug ID: 119988
           Summary: Takes 2 reassociation pass to optimize range if
                    sometimes
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int foo (void);

bool
f10 (int a)
{
  bool v1 = (a != 3);
  bool v2 = (a != 1);
  bool v3 = (a != 4);
  bool v4 = (a != 2);
  bool v5 = (a != 7);
  bool v6 = (a != 5);
  bool v7 = (a != 8);
  bool v8 = (a != 6);
  return v1 && v2 && v3 && v4 && v5 && v6 && v7 && v8;
}

```
At `-O2 -fno-ipa-icf -fno-jump-tables -fno-bit-tests`

GCC is able to optimize this from the IR coming from the C front-end during
reassoc1 but it takes 2 reassoc passes from the IR coming from the C++
front-end.

This is because PHIOPT combine:
```
  <bb 4> [local count: 268435456]:
  _3 = v5_11 & v6_12;
  if (_3 != 0)
    goto <bb 5>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 5> [local count: 134217728]:
  _4 = v7_13 & v8_14;
  _17 = (int) _4;
```
into
```
  _3 = v5_11 & v6_12;
  _4 = v7_13 & v8_14;
  _16 = _3 & _4;
```

And reassoc does this:
```
Optimizing range tests a_6(D) -[1, 1] and -[2, 2] and -[3, 3] and -[4, 4]
 into (unsigned int) a_6(D) + 4294967295 > 3
gimple_simplified to _20 = 1;
gimple_simplified to _21 = _19;
Rank for _17 is 5
Linearized: _16 = _22 & v7_13;
Rank for v6_12 is 5
Rank for v5_11 is 5
Rank for v8_14 is 5
Rank for v7_13 is 5
Optimizing range tests a_6(D) -[5, 5] and -[6, 6] and -[7, 7] and -[8, 8]
 into (unsigned int) a_6(D) + 4294967291 > 3
Transforming _16 = _22 & v7_13;
 into _16 = _25;
```

This is the reduced testcase from gcc.dg/pr46309-2.c which fails after a
phiprop patch which I am working on (59660) but since it can be reproduced
using the C++ front-end; I thought I file it seperately.

Reply via email to