[llvm] [VectorCombine] Combine BinOp with extract/insert to vector BinOp (PR #115213)
    Min-Yih Hsu via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Nov  6 16:59:43 PST 2024
    
    
  
================
@@ -2678,6 +2679,52 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) {
   return true;
 }
 
+/// insert (DstVec, (extract (binop), ExtIdx), InsIdx) -->
+/// shuffl (DstVec, (binop), Mask)
+bool VectorCombine::foldInsExtOfBinOpShuffle(Instruction &I) {
+  Value *DstVec;
+  BinaryOperator *BO;
+  uint64_t ExtIdx, InsIdx;
+  if (!match(&I, m_InsertElt(
+                     m_Value(DstVec),
+                     m_OneUse(m_ExtractElt(m_BinOp(BO), m_ConstantInt(ExtIdx))),
+                     m_ConstantInt(InsIdx))))
+    return false;
+
+  if (!isSafeToSpeculativelyExecute(BO))
+    return false;
+
+  auto *VecTy = cast<FixedVectorType>(I.getType());
----------------
mshockwave wrote:
this will crash if `I` has scalable vector type. You can limit this combine rule to fixed vector only
https://github.com/llvm/llvm-project/pull/115213
    
    
More information about the llvm-commits
mailing list