[llvm] [mlir] [NCFI][OpenMPIRBuilderTest] remove some trivial uses of getAllocatedType (PR #181722)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 16 10:58:18 PST 2026
https://github.com/vtjnash created https://github.com/llvm/llvm-project/pull/181722
These are the required uses of the alloca type, but have trivial access to the expected result of that API call. The remaining uses in unittests are for testing the LLVM API itself.
>From 4d715d4a5fa94331321bc9894c360f388244eba6 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash at gmail.com>
Date: Mon, 16 Feb 2026 18:53:03 +0000
Subject: [PATCH] [NCFI][OpenMPIRBuilderTest] remove some trivial uses of
getAllocatedType
These are the required uses, but have trivial access to the expected
result of the API call. The remaining uses in unittests are for testing
the LLVM API itself.
Co-authored-by: Claude Sonnet 4.5 <noreply at anthropic.com>
---
.../Frontend/OpenMPIRBuilderTest.cpp | 106 +++++++++---------
mlir/include/mlir/IR/BuiltinTypeInterfaces.td | 4 +-
mlir/include/mlir/IR/BuiltinTypes.td | 10 +-
3 files changed, 59 insertions(+), 61 deletions(-)
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 003a831833482..200dda84b13f5 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -654,12 +654,12 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {
++NumBodiesGenerated;
Builder.restoreIP(AllocaIP);
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
Builder.restoreIP(CodeGenIP);
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Value *Cmp = Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
Instruction *ThenTerm, *ElseTerm;
SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
@@ -767,12 +767,12 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
++NumBodiesGenerated;
Builder.restoreIP(AllocaIP);
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
Builder.restoreIP(CodeGenIP);
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Value *Cmp = Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
Instruction *ThenTerm, *ElseTerm;
SplitBlockAndInsertIfThenElse(Cmp, CodeGenIP.getBlock()->getTerminator(),
@@ -1097,12 +1097,12 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
++NumBodiesGenerated;
Builder.restoreIP(AllocaIP);
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
Builder.restoreIP(CodeGenIP);
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Value *Cmp = Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
Instruction *ThenTerm, *ElseTerm;
SplitBlockAndInsertIfThenElse(Cmp, &*Builder.GetInsertPoint(), &ThenTerm,
@@ -1995,9 +1995,9 @@ TEST_F(OpenMPIRBuilderTest, ApplySimdCustomAligned) {
IRBuilder<> Builder(BB);
const int AlignmentValue = 32;
llvm::BasicBlock *sourceBlock = Builder.GetInsertBlock();
- AllocaInst *Alloc1 =
- Builder.CreateAlloca(Builder.getPtrTy(), Builder.getInt64(1));
- LoadInst *Load1 = Builder.CreateLoad(Alloc1->getAllocatedType(), Alloc1);
+ Type *Alloc1Ty = Builder.getPtrTy();
+ AllocaInst *Alloc1 = Builder.CreateAlloca(Alloc1Ty, Builder.getInt64(1));
+ LoadInst *Load1 = Builder.CreateLoad(Alloc1Ty, Alloc1);
MapVector<Value *, Value *> AlignedVars;
AlignedVars.insert({Load1, Builder.getInt64(AlignmentValue)});
@@ -2208,8 +2208,8 @@ TEST_F(OpenMPIRBuilderTest, ApplySimdIf) {
// Generation of if condition
Builder.CreateStore(ConstantInt::get(Type::getInt32Ty(Ctx), 0U), Alloc1);
Builder.CreateStore(ConstantInt::get(Type::getInt32Ty(Ctx), 1U), Alloc2);
- LoadInst *Load1 = Builder.CreateLoad(Alloc1->getAllocatedType(), Alloc1);
- LoadInst *Load2 = Builder.CreateLoad(Alloc2->getAllocatedType(), Alloc2);
+ LoadInst *Load1 = Builder.CreateLoad(Builder.getInt32Ty(), Alloc1);
+ LoadInst *Load2 = Builder.CreateLoad(Builder.getInt32Ty(), Alloc2);
Value *IfCmp = Builder.CreateICmpNE(Load1, Load2);
@@ -2866,7 +2866,8 @@ TEST_F(OpenMPIRBuilderTest, MasterDirective) {
Builder.restoreIP(AllocaIP);
else
Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -2880,8 +2881,7 @@ TEST_F(OpenMPIRBuilderTest, MasterDirective) {
EntryBB = ThenBB->getUniquePredecessor();
// simple instructions for body
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -2948,7 +2948,8 @@ TEST_F(OpenMPIRBuilderTest, MaskedDirective) {
Builder.restoreIP(AllocaIP);
else
Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -2962,8 +2963,7 @@ TEST_F(OpenMPIRBuilderTest, MaskedDirective) {
EntryBB = ThenBB->getUniquePredecessor();
// simple instructions for body
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -3021,7 +3021,8 @@ TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
- AllocaInst *PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ AllocaInst *PrivAI = Builder.CreateAlloca(PrivType);
auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
// actual start for bodyCB
@@ -3032,8 +3033,7 @@ TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
// body begin
Builder.restoreIP(CodeGenIP);
Builder.CreateStore(F->arg_begin(), PrivAI);
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -3274,8 +3274,8 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveThreads) {
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
- AllocaInst *PrivAI =
- Builder.CreateAlloca(F->arg_begin()->getType(), nullptr, "priv.inst");
+ Type *PrivType = F->arg_begin()->getType();
+ AllocaInst *PrivAI = Builder.CreateAlloca(PrivType, nullptr, "priv.inst");
auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -3284,8 +3284,7 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveThreads) {
Builder.restoreIP(CodeGenIP);
Builder.CreateStore(F->arg_begin(), PrivAI);
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -3351,8 +3350,8 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveSimd) {
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
- AllocaInst *PrivAI =
- Builder.CreateAlloca(F->arg_begin()->getType(), nullptr, "priv.inst");
+ Type *PrivType = F->arg_begin()->getType();
+ AllocaInst *PrivAI = Builder.CreateAlloca(PrivType, nullptr, "priv.inst");
auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -3361,8 +3360,7 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveSimd) {
Builder.restoreIP(CodeGenIP);
Builder.CreateStore(F->arg_begin(), PrivAI);
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -3466,7 +3464,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirective) {
Builder.restoreIP(AllocaIP);
else
Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -3480,8 +3479,7 @@ TEST_F(OpenMPIRBuilderTest, SingleDirective) {
EntryBB = ThenBB->getUniquePredecessor();
// simple instructions for body
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -3560,7 +3558,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {
Builder.restoreIP(AllocaIP);
else
Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -3574,8 +3573,7 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {
EntryBB = ThenBB->getUniquePredecessor();
// simple instructions for body
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -3682,7 +3680,8 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {
Builder.restoreIP(AllocaIP);
else
Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
- PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+ Type *PrivType = F->arg_begin()->getType();
+ PrivAI = Builder.CreateAlloca(PrivType);
Builder.CreateStore(F->arg_begin(), PrivAI);
llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
@@ -3696,8 +3695,7 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {
EntryBB = ThenBB->getUniquePredecessor();
// simple instructions for body
- Value *PrivLoad =
- Builder.CreateLoad(PrivAI->getAllocatedType(), PrivAI, "local.use");
+ Value *PrivLoad = Builder.CreateLoad(PrivType, PrivAI, "local.use");
Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
};
@@ -4632,11 +4630,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTeams) {
Builder.restoreIP(CodeGenIP);
// Loading and storing captured pointer and values
Builder.CreateStore(Val128, Local128);
- Value *Val32 = Builder.CreateLoad(ValPtr32->getAllocatedType(), ValPtr32,
- "bodygen.load32");
+ Value *Val32 =
+ Builder.CreateLoad(Builder.getInt32Ty(), ValPtr32, "bodygen.load32");
- LoadInst *PrivLoad128 = Builder.CreateLoad(
- Local128->getAllocatedType(), Local128, "bodygen.local.load128");
+ LoadInst *PrivLoad128 = Builder.CreateLoad(Builder.getInt128Ty(), Local128,
+ "bodygen.local.load128");
Value *Cmp = Builder.CreateICmpNE(
Val32, Builder.CreateTrunc(PrivLoad128, Val32->getType()));
Instruction *ThenTerm, *ElseTerm;
@@ -7164,11 +7162,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTask) {
Builder.restoreIP(CodeGenIP);
// Loading and storing captured pointer and values
Builder.CreateStore(Val128, Local128);
- Value *Val32 = Builder.CreateLoad(ValPtr32->getAllocatedType(), ValPtr32,
- "bodygen.load32");
+ Value *Val32 =
+ Builder.CreateLoad(Builder.getInt32Ty(), ValPtr32, "bodygen.load32");
- LoadInst *PrivLoad128 = Builder.CreateLoad(
- Local128->getAllocatedType(), Local128, "bodygen.local.load128");
+ LoadInst *PrivLoad128 = Builder.CreateLoad(Builder.getInt128Ty(), Local128,
+ "bodygen.local.load128");
Value *Cmp = Builder.CreateICmpNE(
Val32, Builder.CreateTrunc(PrivLoad128, Val32->getType()));
Instruction *ThenTerm, *ElseTerm;
@@ -7580,10 +7578,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroup) {
Builder.restoreIP(CodeGenIP);
// Loading and storing captured pointer and values
InternalStoreInst = Builder.CreateStore(Val128, Local128);
- InternalLoad32 = Builder.CreateLoad(ValPtr32->getAllocatedType(), ValPtr32,
- "bodygen.load32");
+ InternalLoad32 =
+ Builder.CreateLoad(Builder.getInt32Ty(), ValPtr32, "bodygen.load32");
- InternalLoad128 = Builder.CreateLoad(Local128->getAllocatedType(), Local128,
+ InternalLoad128 = Builder.CreateLoad(Builder.getInt128Ty(), Local128,
"bodygen.local.load128");
InternalIfCmp = Builder.CreateICmpNE(
InternalLoad32,
@@ -7671,8 +7669,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
Builder.restoreIP(CodeGenIP);
auto TaskBodyGenCB1 = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
Builder.restoreIP(CodeGenIP);
- LoadInst *LoadValue =
- Builder.CreateLoad(Alloca64->getAllocatedType(), Alloca64);
+ LoadInst *LoadValue = Builder.CreateLoad(Builder.getInt64Ty(), Alloca64);
Value *AddInst = Builder.CreateAdd(LoadValue, Builder.getInt64(64));
Builder.CreateStore(AddInst, Alloca64);
return Error::success();
@@ -7684,8 +7681,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
auto TaskBodyGenCB2 = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
Builder.restoreIP(CodeGenIP);
- LoadInst *LoadValue =
- Builder.CreateLoad(Alloca32->getAllocatedType(), Alloca32);
+ LoadInst *LoadValue = Builder.CreateLoad(Builder.getInt32Ty(), Alloca32);
Value *AddInst = Builder.CreateAdd(LoadValue, Builder.getInt32(32));
Builder.CreateStore(AddInst, Alloca32);
return Error::success();
diff --git a/mlir/include/mlir/IR/BuiltinTypeInterfaces.td b/mlir/include/mlir/IR/BuiltinTypeInterfaces.td
index 9ef08b7020b99..a7ff41e9ab7fe 100644
--- a/mlir/include/mlir/IR/BuiltinTypeInterfaces.td
+++ b/mlir/include/mlir/IR/BuiltinTypeInterfaces.td
@@ -45,8 +45,8 @@ def VectorElementTypeInterface : TypeInterface<"VectorElementTypeInterface"> {
// FloatTypeInterface
//===----------------------------------------------------------------------===//
-def FloatTypeInterface : TypeInterface<"FloatType",
- [VectorElementTypeInterface]> {
+def FloatTypeInterface
+ : TypeInterface<"FloatType", [VectorElementTypeInterface]> {
let cppNamespace = "::mlir";
let description = [{
This type interface should be implemented by all floating-point types. It
diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td
index 806064faeda00..4fde5ef91c87f 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.td
+++ b/mlir/include/mlir/IR/BuiltinTypes.td
@@ -559,8 +559,8 @@ def Builtin_Graph : Builtin_FunctionLike<"Graph", "graph">;
// IndexType
//===----------------------------------------------------------------------===//
-def Builtin_Index : Builtin_Type<"Index", "index",
- [VectorElementTypeInterface]> {
+def Builtin_Index
+ : Builtin_Type<"Index", "index", [VectorElementTypeInterface]> {
let summary = "Integer-like type with unknown platform-dependent bit width";
let description = [{
Syntax:
@@ -590,8 +590,10 @@ def Builtin_Index : Builtin_Type<"Index", "index",
// IntegerType
//===----------------------------------------------------------------------===//
-def Builtin_Integer : Builtin_Type<"Integer", "integer",
- [VectorElementTypeInterface, QuantStorageTypeInterface]> {
+def Builtin_Integer
+ : Builtin_Type<
+ "Integer",
+ "integer", [VectorElementTypeInterface, QuantStorageTypeInterface]> {
let summary = "Integer type with arbitrary precision up to a fixed limit";
let description = [{
Syntax:
More information about the llvm-commits
mailing list