https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114086
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |aldyh at gcc dot gnu.org, | |amacleod at redhat dot com --- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Unfortunately doing the ((682 >> x) & 1) to x & 1 optimization in match.pd isn't possible, we can only use global ranges there and we need path specific range here. Can it be done in VRP pass? Though, I'm afraid I'm quite lost where it actually has the statement optimizations (rather than mere computing of ranges), Aldy/Andrew, any hints? I mean like what old tree-vrp.c was doing in simplify_stmt_using_ranges. Guess we could duplicate that in match.pd for the case which can use global range or doesn't need any range at all. I mean unsigned int foo (int x) { return (0xaaaaaaaaU >> x) & 1; } unsigned int bar (int x) { return (0x55555555U >> x) & 1; } unsigned int baz (int x) { if (x >= 22) __builtin_unreachable (); return (0x5aaaaaU >> x) & 1; } can be optimized even with global ranges (or the first one with no ranges). foo and baz equivalent is x & 1, while bar is (~x) & 1 or (x & 1) ^ 1, dunno what is more canonical.