Skip to content

Commit 58925a4

Browse files
committed
review comments
- change code pattern to avoid calling TTI if we don't have a target specific intrinsics - change type from unsigned to int
1 parent b95d4f3 commit 58925a4

File tree

7 files changed

+25
-28
lines changed

7 files changed

+25
-28
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ class TargetTransformInfo {
897897
unsigned ScalarOpdIdx) const;
898898

899899
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
900-
unsigned ScalarOpdIdx,
901-
bool Default) const;
900+
int ScalarOpdIdx) const;
902901

903902
/// Estimate the overhead of scalarizing an instruction. Insert and Extract
904903
/// are set if the demanded result elements need to be inserted and/or
@@ -1974,8 +1973,7 @@ class TargetTransformInfo::Concept {
19741973
virtual bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
19751974
unsigned ScalarOpdIdx) = 0;
19761975
virtual bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
1977-
unsigned ScalarOpdIdx,
1978-
bool Default) = 0;
1976+
int ScalarOpdIdx) = 0;
19791977
virtual InstructionCost getScalarizationOverhead(VectorType *Ty,
19801978
const APInt &DemandedElts,
19811979
bool Insert, bool Extract,
@@ -2538,10 +2536,8 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
25382536
}
25392537

25402538
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
2541-
unsigned ScalarOpdIdx,
2542-
bool Default) override {
2543-
return Impl.isVectorIntrinsicWithOverloadTypeAtArg(ID, ScalarOpdIdx,
2544-
Default);
2539+
int ScalarOpdIdx) override {
2540+
return Impl.isVectorIntrinsicWithOverloadTypeAtArg(ID, ScalarOpdIdx);
25452541
}
25462542

25472543
InstructionCost getScalarizationOverhead(VectorType *Ty,

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,8 @@ class TargetTransformInfoImplBase {
393393
}
394394

395395
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
396-
unsigned ScalarOpdIdx,
397-
bool Default) const {
398-
return Default;
396+
int ScalarOpdIdx) const {
397+
return ScalarOpdIdx == -1;
399398
}
400399

401400
InstructionCost getScalarizationOverhead(VectorType *Ty,

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
799799
}
800800

801801
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
802-
unsigned ScalarOpdIdx,
803-
bool Default) const {
804-
return Default;
802+
int ScalarOpdIdx) const {
803+
return ScalarOpdIdx == -1;
805804
}
806805

807806
/// Helper wrapper for the DemandedElts variant of getScalarizationOverhead.

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,8 @@ bool TargetTransformInfo::isTargetIntrinsicWithScalarOpAtArg(
613613
}
614614

615615
bool TargetTransformInfo::isVectorIntrinsicWithOverloadTypeAtArg(
616-
Intrinsic::ID ID, unsigned ScalarOpdIdx, bool Default) const {
617-
return TTIImpl->isVectorIntrinsicWithOverloadTypeAtArg(ID, ScalarOpdIdx,
618-
Default);
616+
Intrinsic::ID ID, int ScalarOpdIdx) const {
617+
return TTIImpl->isVectorIntrinsicWithOverloadTypeAtArg(ID, ScalarOpdIdx);
619618
}
620619

621620
InstructionCost TargetTransformInfo::getScalarizationOverhead(

llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ bool DirectXTTIImpl::isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
2525
}
2626
}
2727

28-
bool DirectXTTIImpl::isVectorIntrinsicWithOverloadTypeAtArg(
29-
Intrinsic::ID ID, unsigned ScalarOpdIdx, bool Default) {
28+
bool DirectXTTIImpl::isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
29+
int ScalarOpdIdx) {
3030
switch (ID) {
3131
default:
32-
return Default;
32+
return ScalarOpdIdx == -1;
3333
}
3434
}
3535

llvm/lib/Target/DirectX/DirectXTargetTransformInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class DirectXTTIImpl : public BasicTTIImplBase<DirectXTTIImpl> {
3838
bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
3939
unsigned ScalarOpdIdx);
4040
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
41-
unsigned ScalarOpdIdx,
42-
bool Default);
41+
int ScalarOpdIdx);
4342
};
4443
} // namespace llvm
4544

llvm/lib/Transforms/Scalar/Scalarizer.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class ScalarizerVisitor : public InstVisitor<ScalarizerVisitor, bool> {
280280
bool visit(Function &F);
281281

282282
bool isTriviallyScalarizable(Intrinsic::ID ID);
283+
bool isIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int ScalarOpdIdx);
283284

284285
// InstVisitor methods. They return true if the instruction was scalarized,
285286
// false if nothing changed.
@@ -696,6 +697,13 @@ bool ScalarizerVisitor::isTriviallyScalarizable(Intrinsic::ID ID) {
696697
TTI->isTargetIntrinsicTriviallyScalarizable(ID);
697698
}
698699

700+
bool ScalarizerVisitor::isIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
701+
int ScalarOpdIdx) {
702+
return Intrinsic::isTargetIntrinsic(ID)
703+
? TTI->isVectorIntrinsicWithOverloadTypeAtArg(ID, ScalarOpdIdx)
704+
: isVectorIntrinsicWithOverloadTypeAtArg(ID, ScalarOpdIdx);
705+
}
706+
699707
/// If a call to a vector typed intrinsic function, split into a scalar call per
700708
/// element if possible for the intrinsic.
701709
bool ScalarizerVisitor::splitCall(CallInst &CI) {
@@ -727,8 +735,7 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) {
727735

728736
SmallVector<llvm::Type *, 3> Tys;
729737
// Add return type if intrinsic is overloaded on it.
730-
if (TTI->isVectorIntrinsicWithOverloadTypeAtArg(
731-
ID, -1, isVectorIntrinsicWithOverloadTypeAtArg(ID, -1)))
738+
if (isIntrinsicWithOverloadTypeAtArg(ID, -1))
732739
Tys.push_back(VS->SplitTy);
733740

734741
if (AreAllVectorsOfMatchingSize) {
@@ -768,15 +775,13 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) {
768775
}
769776

770777
Scattered[I] = scatter(&CI, OpI, *OpVS);
771-
if (TTI->isVectorIntrinsicWithOverloadTypeAtArg(
772-
ID, I, isVectorIntrinsicWithOverloadTypeAtArg(ID, I))) {
778+
if (isIntrinsicWithOverloadTypeAtArg(ID, I)) {
773779
OverloadIdx[I] = Tys.size();
774780
Tys.push_back(OpVS->SplitTy);
775781
}
776782
} else {
777783
ScalarOperands[I] = OpI;
778-
if (TTI->isVectorIntrinsicWithOverloadTypeAtArg(
779-
ID, I, isVectorIntrinsicWithOverloadTypeAtArg(ID, I)))
784+
if (isIntrinsicWithOverloadTypeAtArg(ID, I))
780785
Tys.push_back(OpI->getType());
781786
}
782787
}

0 commit comments

Comments
 (0)