[llvm] [IR] Add new CreateVectorInterleave interface and constant fold (PR #150931)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 28 05:49:30 PDT 2025


================
@@ -189,6 +189,24 @@ class LLVM_ABI TargetFolder final : public IRBuilderFolder {
     return nullptr;
   }
 
+  Value *FoldVectorInterleave(ArrayRef<Value *> Ops) const override {
----------------
david-arm wrote:

I'm not sure I understand. Do you mean that I shouldn't be changing any of the folders whatsoever, or that I should be doing something like this in TargetFolder:

```
  Value *FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty,
                             Instruction *FMFSource) const override {
    auto *C1 = dyn_cast<Constant>(LHS);
    auto *C2 = dyn_cast<Constant>(RHS);
    if (C1 && C2)
      return ConstantFoldBinaryIntrinsic(ID, C1, C2, Ty, FMFSource);
    return nullptr;
  }
```

I thought the standard practice in IRBuilder was to apply folds using the folder, i.e. like we do here:

```
Value *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS,
                                            Value *RHS, FMFSource FMFSource,
                                            const Twine &Name) {
  Module *M = BB->getModule();
  Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
  if (Value *V = Folder.FoldBinaryIntrinsic(ID, LHS, RHS, Fn->getReturnType(),
                                            /*FMFSource=*/nullptr))
```

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


More information about the llvm-commits mailing list