Skip to content

Commit 0dcbc1c

Browse files
Iterate over functions in module to check if dec exists
1 parent f5b900d commit 0dcbc1c

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

llvm/lib/Target/AMDGPU/AMDGPUUniformIntrinsicCombine.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,38 +103,22 @@ static bool optimizeUniformIntrinsic(IntrinsicInst &II,
103103
/// Iterates over the Intrinsics use in the function to optimise.
104104
static bool runUniformIntrinsicCombine(Function &F, const UniformityInfo *UI) {
105105
Module *M = F.getParent();
106-
llvm::LLVMContext &Ctx = M->getContext();
107106
// List of AMDGPU intrinsics to optimize if their arguments are uniform.
108107
std::vector<Intrinsic::ID> Intrinsics = {
109108
Intrinsic::amdgcn_permlane64, Intrinsic::amdgcn_readfirstlane,
110109
Intrinsic::amdgcn_readlane, Intrinsic::amdgcn_ballot};
111110

112111
bool IsChanged = false;
113-
// TODO: Vector types can also be optimized, provided generic way to query
114-
// getDeclarationIfExists().
115-
SmallVector<Type *, 7> Tys = {
116-
Type::getInt16Ty(Ctx), // i16
117-
Type::getInt32Ty(Ctx), // i32
118-
Type::getInt64Ty(Ctx), // i64
119-
Type::getHalfTy(Ctx), // Float16
120-
Type::getFloatTy(Ctx), // float
121-
Type::getDoubleTy(Ctx), // double
122-
Type::getBFloatTy(Ctx) // bfloat16
123-
};
124-
// Iterate over each intrinsic in the list and process its uses within F.
125-
for (Intrinsic::ID IID : Intrinsics) {
126-
for (Type *Ty : Tys) {
127-
// Check if the intrinsic is declared in the module with the expected
128-
// type.
129-
if (Function *Intr = Intrinsic::getDeclarationIfExists(M, IID, {Ty})) {
130-
// Iterate over all users of the intrinsic.
131-
for (User *U : Intr->users()) {
132-
// Ensure the user is an intrinsic call within function F.
133-
if (auto *II = dyn_cast<IntrinsicInst>(U)) {
134-
if (II->getFunction() == &F) {
135-
IsChanged |= optimizeUniformIntrinsic(*II, UI);
136-
}
137-
}
112+
for (Function &Func : M->functions()) {
113+
// Continue if intrinsic doesn't exists or not in the intrinsic list.
114+
Intrinsic::ID IID = Func.getIntrinsicID();
115+
if (IID == Intrinsic::not_intrinsic || !llvm::is_contained(Intrinsics, IID))
116+
continue;
117+
118+
for (User *U : Func.users()) {
119+
if (auto *II = dyn_cast<IntrinsicInst>(U)) {
120+
if (II->getFunction() == &F) {
121+
IsChanged |= optimizeUniformIntrinsic(*II, UI);
138122
}
139123
}
140124
}
@@ -151,9 +135,6 @@ class AMDGPUUniformIntrinsicCombineLegacy : public FunctionPass {
151135
}
152136
bool runOnFunction(Function &F) override;
153137
void getAnalysisUsage(AnalysisUsage &AU) const override {
154-
AU.setPreservesCFG();
155-
AU.addRequired<UniformityInfoWrapperPass>();
156-
AU.addRequired<TargetPassConfig>();
157138
AU.addPreserved<UniformityInfoWrapperPass>();
158139
}
159140
};

0 commit comments

Comments
 (0)