[llvm] [InstCombine] Fold `((A ^ B) & C) | A` -> `A | (B & C)` (PR #76572)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 03:24:37 PST 2024


https://github.com/nikic commented:

I think this list of transforms has reached the point where we need to generalize it if we want to keep adding increasingly exotic variants to it.

The general transform here is that in `x | y` we can simplify x by replacing occurrences of y with 0 -- as long as we only look through bitwise operations. Similar for & and -1.

If we don't care about multi-use, this could be done with https://github.com/llvm/llvm-project/blob/9b7cf5bfb08b6e506216ef354dfd61adb15acbff/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L1225 + a bitwise op limit.

https://github.com/llvm/llvm-project/pull/76572


More information about the llvm-commits mailing list