[Bug tree-optimization/86909] Missing common subexpression elimination for types other than int

"pinskia at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86909

Drea Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|13.1.0                      |

--- Comment #4 from Drea Pinski <pinskia at gcc dot gnu.org> ---
GCC 13 optimizes this almost all the way:
        ldrb    w1, [x0, 1]
        cmp     w1, 255
        beq     .L4
        cmp     w1, 7
        bhi     .L4
        ret
.L4:
        mov     w0, 0

After pre/"commoning" we get on the trunk:
```
  if (_5 != 255)
    goto <bb 3>; [78.28%]
  else
    goto <bb 5>; [21.72%]

  <bb 3> [local count: 840525096]:
  i_4 = (int) _5;
  _17 = (unsigned int) i_4;
  _16 = _5 == 7;
  _15 = _17 <= 6;
  _12 = _15 | _16;
  if (_12 != 0)
    goto <bb 4>; [99.28%]
  else
    goto <bb 5>; [0.72%]
```

Then reassociation is able to optmize it to:
```
  if (_5 != 255)
    goto <bb 3>; [78.28%]
  else
    goto <bb 5>; [21.72%]

  <bb 3> [local count: 840525096]:
  i_4 = (int) _5;
  _17 = (unsigned int) i_4;
  _16 = _5 == 7;
  _8 = _5 <= 7;
  _15 = _17 <= 6;
  _12 = _8;
  if (_12 != 0)
    goto <bb 4>; [99.28%]
  else
    goto <bb 5>; [0.72%]
```

But not combine the 2 ifs.

So the question is if inside pre we could do better and optimize:
```
  i_4 = (int) _5;
  _17 = (unsigned int) i_4;
  _16 = _5 == 7;
  _15 = _17 <= 6;
  _12 = _15 | _16;
```
into just `_5 <= 7` and then `_5 <= 7 && _5 != 255` just becomes `_5 <= 7`.

Looks like a mismatch in the types which is exposing that:
```
  <bb 15> [local count: 0]:
  if (i_4 == 6)
    goto <bb 16>; [34.00%]
  else
    goto <bb 17>; [66.00%]

  <bb 16> [local count: 12149537]:
  _13 = &in_3(D)->a;
  goto <bb 19>; [100.00%]

  <bb 17> [local count: 1]:
  if (_5 == 7)
    goto <bb 18>; [75.61%]
  else
    goto <bb 19>; [24.39%]
```

i_4 is:
  i_4 = (int) _5;
  unsigned char _5;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.