[llvm] [InstCombine] Fold selects into masked loads (PR #160522)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 07:36:48 PDT 2025


================
@@ -4611,5 +4611,16 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
       return replaceOperand(SI, 2, ConstantInt::get(FalseVal->getType(), 0));
   }
 
+  Value *MaskedLoadPtr;
+  const APInt *MaskedLoadAlignment;
+  if (match(TrueVal,
+            m_MaskedLoad(m_Value(MaskedLoadPtr), m_APInt(MaskedLoadAlignment),
+                         m_Specific(CondVal), m_Value())))
----------------
nikic wrote:

If you are already using PatternMatch, the more idiomatic way to do this would be `m_OneUse(m_MakedLoad(...))`.

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


More information about the llvm-commits mailing list