@@ -103,38 +103,22 @@ static bool optimizeUniformIntrinsic(IntrinsicInst &II,
103
103
// / Iterates over the Intrinsics use in the function to optimise.
104
104
static bool runUniformIntrinsicCombine (Function &F, const UniformityInfo *UI) {
105
105
Module *M = F.getParent ();
106
- llvm::LLVMContext &Ctx = M->getContext ();
107
106
// List of AMDGPU intrinsics to optimize if their arguments are uniform.
108
107
std::vector<Intrinsic::ID> Intrinsics = {
109
108
Intrinsic::amdgcn_permlane64, Intrinsic::amdgcn_readfirstlane,
110
109
Intrinsic::amdgcn_readlane, Intrinsic::amdgcn_ballot};
111
110
112
111
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);
138
122
}
139
123
}
140
124
}
@@ -151,9 +135,6 @@ class AMDGPUUniformIntrinsicCombineLegacy : public FunctionPass {
151
135
}
152
136
bool runOnFunction (Function &F) override ;
153
137
void getAnalysisUsage (AnalysisUsage &AU) const override {
154
- AU.setPreservesCFG ();
155
- AU.addRequired <UniformityInfoWrapperPass>();
156
- AU.addRequired <TargetPassConfig>();
157
138
AU.addPreserved <UniformityInfoWrapperPass>();
158
139
}
159
140
};
0 commit comments