[llvm] [polly] [IRBuilder] Remove unused AllocTy argument (PR #222667)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 07:10:23 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/222667

This argument is not used at all. The size is explicitly passed in a separate argument.

>From a400bbc81633296fa8a65a1c37d40640c89f5c1b Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 10 Sep 2026 16:08:26 +0200
Subject: [PATCH] [IRBuilder] Remove unused AllocTy argument

This argument is not used at all. The size is explicitly passed
in a separate argument.
---
 llvm/examples/BrainF/BrainF.cpp           |  3 +--
 llvm/include/llvm/IR/IRBuilder.h          | 14 ++++++--------
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp |  4 ++--
 llvm/lib/IR/Core.cpp                      |  7 +++----
 llvm/lib/IR/IRBuilder.cpp                 | 13 ++++++-------
 polly/lib/CodeGen/IslNodeBuilder.cpp      |  3 +--
 6 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp
index 14e135eb464c8..f4c7804dc8109 100644
--- a/llvm/examples/BrainF/BrainF.cpp
+++ b/llvm/examples/BrainF/BrainF.cpp
@@ -91,8 +91,7 @@ void BrainF::header(LLVMContext& C) {
   Type* IntPtrTy = IntegerType::getInt32Ty(C);
   Type* Int8Ty = IntegerType::getInt8Ty(C);
   Constant* allocsize = ConstantInt::get(IntPtrTy, 1);
-  ptr_arr = builder->CreateMalloc(IntPtrTy, Int8Ty, allocsize, val_mem, nullptr,
-                                  "arr");
+  ptr_arr = builder->CreateMalloc(IntPtrTy, allocsize, val_mem, nullptr, "arr");
 
   //call void @llvm.memset.p0i8.i32(i8 *%arr, i8 0, i32 %d, i1 0)
   {
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 8e1089a9770b0..8b5fa73c9c3e9 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -633,20 +633,18 @@ class IRBuilderBase {
         Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
   }
 
-  LLVM_ABI CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy,
-                                  Value *AllocSize, Value *ArraySize,
+  LLVM_ABI CallInst *CreateMalloc(Type *IntPtrTy, Value *AllocSize,
+                                  Value *ArraySize,
                                   ArrayRef<OperandBundleDef> OpB,
                                   Function *MallocF = nullptr,
                                   const Twine &Name = "");
 
   /// CreateMalloc - Generate the IR for a call to malloc:
-  /// 1. Compute the malloc call's argument as the specified type's size,
-  ///    possibly multiplied by the array size if the array size is not
-  ///    constant 1.
+  /// 1. Compute the malloc call's argument as AllocSize, possibly multiplied
+  ///    by the array size if the array size is not constant 1.
   /// 2. Call malloc with that argument.
-  LLVM_ABI CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy,
-                                  Value *AllocSize, Value *ArraySize,
-                                  Function *MallocF = nullptr,
+  LLVM_ABI CallInst *CreateMalloc(Type *IntPtrTy, Value *AllocSize,
+                                  Value *ArraySize, Function *MallocF = nullptr,
                                   const Twine &Name = "");
   /// Generate the IR for a call to the builtin free function.
   LLVM_ABI CallInst *CreateFree(Value *Source,
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 1a9ed6d9f69ea..6d9b9fc4fcea6 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5553,8 +5553,8 @@ Error OpenMPIRBuilder::emitScanBasedDirectiveDeclsIR(
       Type *IntPtrTy = Builder.getInt32Ty();
       Constant *Allocsize = ConstantExpr::getSizeOf(ScanVarsType[i]);
       Allocsize = ConstantExpr::getTruncOrBitCast(Allocsize, IntPtrTy);
-      Value *Buff = Builder.CreateMalloc(IntPtrTy, ScanVarsType[i], Allocsize,
-                                         AllocSpan, nullptr, "arr");
+      Value *Buff =
+          Builder.CreateMalloc(IntPtrTy, Allocsize, AllocSpan, nullptr, "arr");
       Builder.CreateStore(Buff, (*(ScanRedInfo->ScanBuffPtrs))[ScanVars[i]]);
     }
     return Error::success();
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index d1ee8411e392c..26ce1ecee760d 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -4009,8 +4009,7 @@ LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
   Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
   Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
   AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
-  return wrap(unwrap(B)->CreateMalloc(ITy, unwrap(Ty), AllocSize, nullptr,
-                                      nullptr, Name));
+  return wrap(unwrap(B)->CreateMalloc(ITy, AllocSize, nullptr, nullptr, Name));
 }
 
 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
@@ -4018,8 +4017,8 @@ LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
   Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
   Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
   AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
-  return wrap(unwrap(B)->CreateMalloc(ITy, unwrap(Ty), AllocSize, unwrap(Val),
-                                      nullptr, Name));
+  return wrap(
+      unwrap(B)->CreateMalloc(ITy, AllocSize, unwrap(Val), nullptr, Name));
 }
 
 LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index 21fc73b9c084e..52cb9daba6582 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -346,8 +346,8 @@ static bool isConstantOne(const Value *Val) {
   return CVal && CVal->isOne();
 }
 
-CallInst *IRBuilderBase::CreateMalloc(Type *IntPtrTy, Type *AllocTy,
-                                      Value *AllocSize, Value *ArraySize,
+CallInst *IRBuilderBase::CreateMalloc(Type *IntPtrTy, Value *AllocSize,
+                                      Value *ArraySize,
                                       ArrayRef<OperandBundleDef> OpB,
                                       Function *MallocF, const Twine &Name) {
   // malloc(type) becomes:
@@ -389,12 +389,11 @@ CallInst *IRBuilderBase::CreateMalloc(Type *IntPtrTy, Type *AllocTy,
   return MCall;
 }
 
-CallInst *IRBuilderBase::CreateMalloc(Type *IntPtrTy, Type *AllocTy,
-                                      Value *AllocSize, Value *ArraySize,
-                                      Function *MallocF, const Twine &Name) {
+CallInst *IRBuilderBase::CreateMalloc(Type *IntPtrTy, Value *AllocSize,
+                                      Value *ArraySize, Function *MallocF,
+                                      const Twine &Name) {
 
-  return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
-                      Name);
+  return CreateMalloc(IntPtrTy, AllocSize, ArraySize, {}, MallocF, Name);
 }
 
 /// CreateFree - Generate the IR for a call to the builtin free function.
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index 50de49b37a6c2..50027f898b174 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -1423,8 +1423,7 @@ void IslNodeBuilder::allocateNewArrays(BBPair StartExitBlocks) {
       Builder.SetInsertPoint(StartBlock,
                              StartBlock->getTerminator()->getIterator());
       auto *CreatedArray = Builder.CreateMalloc(
-          IntPtrTy, SAI->getElementType(),
-          ConstantInt::get(Type::getInt64Ty(Ctx), Size),
+          IntPtrTy, ConstantInt::get(Type::getInt64Ty(Ctx), Size),
           ConstantInt::get(Type::getInt64Ty(Ctx), ArraySizeInt), nullptr,
           SAI->getName());
 



More information about the llvm-commits mailing list