https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111541
Bug ID: 111541 Summary: missing optimization x & ~c | (y | c) -> x | (y | c) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vanyacpp at gmail dot com Target Milestone: --- On this function clang generates shorter code: unsigned foo(unsigned x, unsigned y, unsigned c) { return x & ~c | (y | c); } Clang notices that the expression can be simplified to x | (y | c). It would be great if GCC can do the same. https://gcc.godbolt.org/z/dMo4nEjrs This issue is symmetric to the one described in PR 98710. The idea behind this simplification is the following: when we are working with bitsets, "|" can be read as adding bits and "&~" as removing. Therefore the expression "x & ~c | (y | c)" can be read as removing "c" from "x" and then adding "y | c". So the simplification x & ~c | (y | c) -> x | (y | c) means there is no need to remove "c" if later we add something containing "c".