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

            Bug ID: 112383
           Summary: `a&=CST; (a&b) != a` and `((~b) & a) & CST != 0`
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int f1(unsigned a, unsigned b)
{
        a &= 0x11;
        return (a&b) != a;
}


int f2(unsigned a, unsigned b)
{
        int d = 0x11;
        int e = (~b) & a;
        return (e&d) != 0;
}
```

These 2 should produce the same code.

Likewise for:
```

int fn1(unsigned a, unsigned b, unsigned c)
{
        a &= c;
        return (a&b) != a;
}


int fn2(unsigned a, unsigned b, unsigned c)
{
        int d = c;
        int e = (~b) & a;
        return (e&d) != 0;
}
```

Note clang (LLVM) only produces the same code for f1/f2 pair, it misses the
Canonicalization for fn1/fn2 too.

Note for gimple f1/fn1 is simplier and most likely should be canonical.

Reply via email to