[llvm] [InstCombine] Optimize 'xor-and-select' sequence to 'or' for bool (PR #66394)

Bryan Chan via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 09:51:03 PDT 2023


================
@@ -3202,6 +3202,14 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
     }
   }
 
+  // select (~b & a), a, b -> or a, b
+  // only for scalar types
+  if (match(CondVal, m_And(m_Not(m_Specific(FalseVal)), m_Specific(TrueVal))) &&
----------------
bryanpkc wrote:

Can `m_c_And` be used here? Also, you should avoid the transformation if `CondVal` has more than one use. I'd also suggest moving this code to around line 3088, to group it with other simplifications of select with conditions based on the two value operands.

Consider simplifying the mirror expresison `select (~a | b), a, b` to `~(a ^ b)`, if it isn't already.

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


More information about the llvm-commits mailing list