https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117338
Bug ID: 117338 Summary: VRP changing `(a & 1) == 0` into `(bool)~a` gets in the way of ccmp generation Product: gcc Version: 15.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: ``` void doit(void); void f(int a, int b) { a &= 1; if (a == 0 && b > 0) doit(); } ``` At -O1 (or -O2 -fno-tree-vrp) GCC produces: ``` f: tst x0, 1 ccmp w1, 0, 4, eq bgt .L4 ``` But then at -O2 GCC produces: ``` f: cmp w1, 0 cset w1, gt bics wzr, w1, w0 bne .L4 ``` This is because the ccmp generation code does not realize: ``` _9 = ~a_5(D); _1 = (_Bool) _9; ``` is the same as `(a_5 & 1) == 1`. The same is true of just: ``` void f(int a, int b) { a &= 1; if (a != 0 && b > 0) doit(); } ``` Which has the same issue too but does not have the ! part to it. Note this is related to PR 94174's test1 but not the same issue.