Skip to content

Commit 6067351

Browse files
committed
move isTriviallyScalarizable to VectorUtils
1 parent 6f144fd commit 6067351

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

llvm/include/llvm/Analysis/VectorUtils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,20 @@ inline Type *ToVectorTy(Type *Scalar, unsigned VF) {
144144
/// This method returns true if the intrinsic's argument types are all scalars
145145
/// for the scalar form of the intrinsic and all vectors (or scalars handled by
146146
/// isVectorIntrinsicWithScalarOpAtArg) for the vector form of the intrinsic.
147+
///
148+
/// Note: isTriviallyVectorizable implies isTriviallyScalarizable.
147149
bool isTriviallyVectorizable(Intrinsic::ID ID);
148150

151+
/// Identify if the intrinsic is trivially scalarizable.
152+
/// This method returns true following the same predicates of
153+
/// isTriviallyVectorizable.
154+
155+
/// Note: There are intrinsics where implementing vectorization for the
156+
/// intrinsic is redundant, but we want to implement scalarization of the
157+
/// vector. To prevent the requirement that an intrinsic also implements
158+
/// vectorization we provide this seperate function.
159+
bool isTriviallyScalarizable(Intrinsic::ID ID, const TargetTransformInfo *TTI);
160+
149161
/// Identifies if the vector form of the intrinsic has a scalar operand.
150162
/// \p TTI is used to consider target specific intrinsics, if no target specific
151163
/// intrinsics will be considered then it is appropriate to pass in nullptr.

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
113113
}
114114
}
115115

116+
bool llvm::isTriviallyScalarizable(Intrinsic::ID ID,
117+
const TargetTransformInfo *TTI) {
118+
if (isTriviallyVectorizable(ID))
119+
return true;
120+
121+
if (TTI && Intrinsic::isTargetIntrinsic(ID))
122+
return TTI->isTargetIntrinsicTriviallyScalarizable(ID);
123+
124+
// TODO: Move frexp to isTriviallyVectorizable.
125+
// https://github.com/llvm/llvm-project/issues/112408
126+
switch (ID) {
127+
case Intrinsic::frexp:
128+
return true;
129+
}
130+
return false;
131+
}
132+
116133
/// Identifies if the vector form of the intrinsic has a scalar operand.
117134
bool llvm::isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
118135
unsigned ScalarOpdIdx,

llvm/lib/Transforms/Scalar/Scalarizer.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ class ScalarizerVisitor : public InstVisitor<ScalarizerVisitor, bool> {
279279

280280
bool visit(Function &F);
281281

282-
bool isTriviallyScalarizable(Intrinsic::ID ID);
283-
284282
// InstVisitor methods. They return true if the instruction was scalarized,
285283
// false if nothing changed.
286284
bool visitInstruction(Instruction &I) { return false; }
@@ -683,19 +681,6 @@ bool ScalarizerVisitor::splitBinary(Instruction &I, const Splitter &Split) {
683681
return true;
684682
}
685683

686-
bool ScalarizerVisitor::isTriviallyScalarizable(Intrinsic::ID ID) {
687-
if (isTriviallyVectorizable(ID))
688-
return true;
689-
// TODO: Move frexp to isTriviallyVectorizable.
690-
// https://github.com/llvm/llvm-project/issues/112408
691-
switch (ID) {
692-
case Intrinsic::frexp:
693-
return true;
694-
}
695-
return Intrinsic::isTargetIntrinsic(ID) &&
696-
TTI->isTargetIntrinsicTriviallyScalarizable(ID);
697-
}
698-
699684
/// If a call to a vector typed intrinsic function, split into a scalar call per
700685
/// element if possible for the intrinsic.
701686
bool ScalarizerVisitor::splitCall(CallInst &CI) {
@@ -715,7 +700,7 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) {
715700

716701
Intrinsic::ID ID = F->getIntrinsicID();
717702

718-
if (ID == Intrinsic::not_intrinsic || !isTriviallyScalarizable(ID))
703+
if (ID == Intrinsic::not_intrinsic || !isTriviallyScalarizable(ID, TTI))
719704
return false;
720705

721706
// unsigned NumElems = VT->getNumElements();
@@ -1088,7 +1073,7 @@ bool ScalarizerVisitor::visitExtractValueInst(ExtractValueInst &EVI) {
10881073
if (!F)
10891074
return false;
10901075
Intrinsic::ID ID = F->getIntrinsicID();
1091-
if (ID == Intrinsic::not_intrinsic || !isTriviallyScalarizable(ID))
1076+
if (ID == Intrinsic::not_intrinsic || !isTriviallyScalarizable(ID, TTI))
10921077
return false;
10931078
// Note: Fall through means Operand is a`CallInst` and it is defined in
10941079
// `isTriviallyScalarizable`.

0 commit comments

Comments
 (0)