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

Bryan Chan via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 15:35:50 PDT 2023


================
@@ -3112,6 +3112,26 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
     return SelectInst::Create(FalseVal, One, AndV);
   }
 
+  // select (~b & a), a, b -> or a, b
+  // only for scalar types
+  if (match(CondVal, m_c_And(m_Not(m_Specific(FalseVal)), m_Specific(TrueVal))) &&
+      TrueVal->getType()->isIntegerTy(1) &&
+      FalseVal->getType()->isIntegerTy(1) &&
+      CondVal->getType()->isIntegerTy(1) &&
----------------
bryanpkc wrote:

These scalar type checks are not necessary. When given vector operands, the `select` instruction will perform the selection element by element.

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


More information about the llvm-commits mailing list