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

            Bug ID: 126750
           Summary: a & b (and a | b) -> a (or b) if a == b is known
                    without dom
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 85316, 126010
  Target Milestone: ---

Take:
```
unsigned f(unsigned a, unsigned b)
{
    if (b != a) __builtin_unreachable();
    unsigned t = b & a;
    return t != b;
}
unsigned f0(unsigned a, unsigned b)
{
    if (b != a) __builtin_unreachable();
    unsigned t = b & a;
    return t != b;
}
unsigned g(unsigned a, unsigned b)
{
    if (b != a) __builtin_unreachable();
    unsigned t = b | a;
    return t != b;
}
unsigned g0(unsigned a, unsigned b)
{
    if (b != a) __builtin_unreachable();
    unsigned t = b | a;
    return t != b;
}
```

These are both should be optimized to 0 since we know that a == b so `a & b` is
a and b.

I suspect we want to optimize `b & a` (and `a | b`) into the first operand if
we know that `a == b` and then `a != b` will be optimize by the rest of VRP.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126010
[Bug 126010] [meta-bug] Remove DOM

Reply via email to