[llvm] [InstCombine] Constant fold binops through `vector.insert` (PR #164624)
    Nikita Popov via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Oct 23 02:04:38 PDT 2025
    
    
  
================
@@ -2334,6 +2360,36 @@ Instruction *InstCombinerImpl::foldVectorBinop(BinaryOperator &Inst) {
   assert(cast<VectorType>(RHS->getType())->getElementCount() ==
          cast<VectorType>(Inst.getType())->getElementCount());
 
+  auto foldConstantsThroughSubVectorInsert =
+      [&](Constant *Dest, Value *DestIdx, Type *SubVecType, Constant *SubVector,
+          Constant *Splat, bool SplatLHS) -> Instruction * {
+    SubVector =
+        constantFoldBinOpWithSplat(Opcode, SubVector, Splat, SplatLHS, DL);
+    Dest = constantFoldBinOpWithSplat(Opcode, Dest, Splat, SplatLHS, DL);
+    if (!SubVector || !Dest)
+      return nullptr;
+    auto *InsertVector =
+        Builder.CreateInsertVector(Dest->getType(), Dest, SubVector, DestIdx);
+    InsertVector->removeFromParent();
----------------
nikic wrote:
We shouldn't do this. Use something like `return replaceInstUsesWith(Inst, InsertVector)` instead.
https://github.com/llvm/llvm-project/pull/164624
    
    
More information about the llvm-commits
mailing list