Since or disjoint here can be regarded as xor, ((select C1, C2) | A) ^ C3 can be (select C1, C2) ^ C3 ^ A) and then we get (select C1^C3, C2^C3) | A).
Real-world motivation
This snippet of IR is derived from zstd/lib/compress/zstd_compress_literals.c@ZSTD_compressLiterals (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, contact me to get them, please.
Let me know if you can confirm that it's an optimization opportunity, thanks.
Alive2 proof: https://alive2.llvm.org/ce/z/oEmX9u
Motivating example
can be folded to
Since
or disjoint
here can be regarded asxor
,((select C1, C2) | A) ^ C3
can be(select C1, C2) ^ C3 ^ A)
and then we get(select C1^C3, C2^C3) | A)
.Real-world motivation
This snippet of IR is derived from zstd/lib/compress/zstd_compress_literals.c@ZSTD_compressLiterals (after O3 pipeline). The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, contact me to get them, please.
Let me know if you can confirm that it's an optimization opportunity, thanks.