https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112395
Bug ID: 112395 Summary: `CST1| (x & CST0)` -> `0x1e | x` iff `x&CST0` known zero bits outside of CST1 is known to be 0 Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- As reported at : https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635206.html An exmaple is: ``` unsigned f(unsigned x){ if(x>=32)__builtin_unreachable(); return 30|(x&1); // --> 30|x } ``` 30 is 0x1e and x has a range of [0, 31] (which has a nonzero bits of 0x1f). The &1 part can be removed from 30|(x&1) as 30 will set every bit except for the first bit. I think the following will work. ``` (simplify (bit_ior (bit_and:s @0 INTEGER_CST@1) INTEGER_CST@2) (if (wi::bit_and_not (wi::bit_and_not (tree_nonzero_bits (@0), wi::to_wide (@1)), wi::to_wide (@0)) == 0) (bit_ior @0 @2)) ```