Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,7 @@ void ModuleCallsiteContextGraph::updateAllocationCall(

void IndexCallsiteContextGraph::updateAllocationCall(CallInfo &Call,
AllocationType AllocType) {
auto *AI = Call.call().dyn_cast<AllocInfo *>();
auto *AI = dyn_cast_if_present<AllocInfo *>(Call.call());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the following assert, this should be just cast<>.

assert(AI);
assert(AI->Versions.size() > Call.cloneNo());
AI->Versions[Call.cloneNo()] = (uint8_t)AllocType;
Expand All @@ -3560,7 +3560,7 @@ ModuleCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const {

AllocationType
IndexCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const {
const auto *AI = Call.call().dyn_cast<AllocInfo *>();
const auto *AI = dyn_cast_if_present<AllocInfo *>(Call.call());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, directly dereferenced.

assert(AI->Versions.size() > Call.cloneNo());
return (AllocationType)AI->Versions[Call.cloneNo()];
}
Expand All @@ -3579,7 +3579,7 @@ void ModuleCallsiteContextGraph::updateCall(CallInfo &CallerCall,

void IndexCallsiteContextGraph::updateCall(CallInfo &CallerCall,
FuncInfo CalleeFunc) {
auto *CI = CallerCall.call().dyn_cast<CallsiteInfo *>();
auto *CI = dyn_cast_if_present<CallsiteInfo *>(CallerCall.call());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also has an assert.

assert(CI &&
"Caller cannot be an allocation which should not have profiled calls");
assert(CI->Clones.size() > CallerCall.cloneNo());
Expand Down Expand Up @@ -3617,10 +3617,11 @@ IndexCallsiteContextGraph::cloneFunctionForCallsite(
// The next clone number is the current size of versions array.
// Confirm this matches the CloneNo provided by the caller, which is based on
// the number of function clones we have.
assert(CloneNo ==
(isa<AllocInfo *>(Call.call())
? Call.call().dyn_cast<AllocInfo *>()->Versions.size()
: Call.call().dyn_cast<CallsiteInfo *>()->Clones.size()));
assert(
CloneNo ==
(isa<AllocInfo *>(Call.call())
? dyn_cast_if_present<AllocInfo *>(Call.call())->Versions.size()
: dyn_cast_if_present<CallsiteInfo *>(Call.call())->Clones.size()));
// Walk all the instructions in this function. Create a new version for
// each (by adding an entry to the Versions/Clones summary array), and copy
// over the version being called for the function clone being cloned here.
Expand All @@ -3630,13 +3631,13 @@ IndexCallsiteContextGraph::cloneFunctionForCallsite(
for (auto &Inst : CallsWithMetadataInFunc) {
// This map always has the initial version in it.
assert(Inst.cloneNo() == 0);
if (auto *AI = Inst.call().dyn_cast<AllocInfo *>()) {
if (auto *AI = dyn_cast_if_present<AllocInfo *>(Inst.call())) {
assert(AI->Versions.size() == CloneNo);
// We assign the allocation type later (in updateAllocationCall), just add
// an entry for it here.
AI->Versions.push_back(0);
} else {
auto *CI = Inst.call().dyn_cast<CallsiteInfo *>();
auto *CI = dyn_cast_if_present<CallsiteInfo *>(Inst.call());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be cast<> which implies above can be dyn_cast<>.

assert(CI && CI->Clones.size() == CloneNo);
// We assign the clone number later (in updateCall), just add an entry for
// it here.
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10354,7 +10354,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
SameNodesEstimated = false;
if (!E2 && InVectors.size() == 1) {
unsigned VF = E1.getVectorFactor();
if (Value *V1 = InVectors.front().dyn_cast<Value *>()) {
if (Value *V1 = dyn_cast_if_present<Value *>(InVectors.front())) {
VF = std::max(VF,
cast<FixedVectorType>(V1->getType())->getNumElements());
} else {
Expand All @@ -10370,7 +10370,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
auto P = InVectors.front();
Cost += createShuffle(&E1, E2, Mask);
unsigned VF = Mask.size();
if (Value *V1 = P.dyn_cast<Value *>()) {
if (Value *V1 = dyn_cast_if_present<Value *>(P)) {
VF = std::max(VF,
getNumElements(V1->getType()));
} else {
Expand Down Expand Up @@ -10435,7 +10435,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
ArrayRef<int> Mask) {
ShuffleCostBuilder Builder(TTI);
SmallVector<int> CommonMask(Mask);
Value *V1 = P1.dyn_cast<Value *>(), *V2 = P2.dyn_cast<Value *>();
Value *V1 = dyn_cast_if_present<Value *>(P1);
Value *V2 = dyn_cast_if_present<Value *>(P2);
unsigned CommonVF = Mask.size();
InstructionCost ExtraCost = 0;
auto GetNodeMinBWAffectedCost = [&](const TreeEntry &E,
Expand Down Expand Up @@ -10870,7 +10871,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
transformMaskAfterShuffle(CommonMask, CommonMask);
VF = std::max<unsigned>(VF, CommonMask.size());
} else if (const auto *InTE =
InVectors.front().dyn_cast<const TreeEntry *>()) {
dyn_cast_if_present<const TreeEntry *>(InVectors.front())) {
VF = std::max(VF, InTE->getVectorFactor());
} else {
VF = std::max(
Expand Down
Loading