[llvm] [InstCombine] Bubble splices of binop operands to their result (PR #179432)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 3 07:14:22 PST 2026


================
@@ -2392,6 +2392,48 @@ static Constant *constantFoldBinOpWithSplat(unsigned Opcode, Constant *Vector,
   return ConstantFoldBinaryOpOperands(Opcode, LHS, RHS, DL);
 }
 
+template <Intrinsic::ID SpliceID>
+static Instruction *foldSpliceBinOp(BinaryOperator &Inst,
+                                    InstCombiner::BuilderTy &Builder) {
+  Value *LHS = Inst.getOperand(0), *RHS = Inst.getOperand(1);
+  auto CreateBinOpSplice = [&](Value *X, Value *Y, Value *Z, Value *Offset) {
+    Value *V = Builder.CreateBinOp(Inst.getOpcode(), X, Y, Inst.getName());
+    if (auto *BO = dyn_cast<BinaryOperator>(V))
+      BO->copyIRFlags(&Inst);
+    Module *M = Inst.getModule();
+    Function *F = Intrinsic::getOrInsertDeclaration(M, SpliceID, V->getType());
+    return CallInst::Create(F, {V, Z, Offset});
+  };
+  Value *V1, *V2, *V3, *Offset;
+  if (match(LHS,
+            m_Intrinsic<SpliceID>(m_Value(V1), m_Value(V3), m_Value(Offset)))) {
+    // Op(splice(V1, V3, offset), splice(V2, V3, offset))
+    // -> splice(Op(V1, V2), V3, offset)
----------------
dtcxzyw wrote:

`splice(V1, V3, offset)` may contain elements from V3. It should be transformed into `splice(Op(V1, V2), Op(V1, V3), offset)`. I think this canonicalization is useful only when V3 is poison.


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


More information about the llvm-commits mailing list