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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 6 10:34:30 PST 2024


dtcxzyw wrote:

> 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.

Alive2: https://alive2.llvm.org/ce/z/vgBZfy
I will post a patch later.


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


More information about the llvm-commits mailing list